|
1 | 1 | using System;
|
2 | 2 | using System.Collections.Generic;
|
3 | 3 | using System.Collections.Immutable;
|
| 4 | +using System.IO; |
4 | 5 | using System.Linq;
|
5 | 6 | using Xunit;
|
6 | 7 | using Xunit.Sdk;
|
@@ -51,85 +52,6 @@ public void SameType_Success(
|
51 | 52 | Assert.Equivalent(expected, actual);
|
52 | 53 | }
|
53 | 54 |
|
54 |
| - [Fact] |
55 |
| - public void DateTime_Success() |
56 |
| - { |
57 |
| - var expected = new DateTime(2022, 12, 1, 1, 3, 1); |
58 |
| - var actual = new DateTime(2022, 12, 1, 1, 3, 1); |
59 |
| - |
60 |
| - Assert.Equivalent(expected, actual); |
61 |
| - } |
62 |
| - |
63 |
| - [Fact] |
64 |
| - public void DateTimeOffset_Success() |
65 |
| - { |
66 |
| - var expected = new DateTimeOffset(2022, 12, 1, 1, 3, 1, TimeSpan.Zero); |
67 |
| - var actual = new DateTimeOffset(2022, 12, 1, 1, 3, 1, TimeSpan.Zero); |
68 |
| - |
69 |
| - Assert.Equivalent(expected, actual); |
70 |
| - } |
71 |
| - |
72 |
| - [Fact] |
73 |
| - public void StringToDateTime_Success() |
74 |
| - { |
75 |
| - var expected = "2022-12-01T01:03:01.0000000"; |
76 |
| - var actual = new DateTime(2022, 12, 1, 1, 3, 1); |
77 |
| - |
78 |
| - Assert.Equivalent(expected, actual); |
79 |
| - } |
80 |
| - |
81 |
| - [Fact] |
82 |
| - public void DateTime_Failure() |
83 |
| - { |
84 |
| - var expected = new DateTime(2022, 12, 1, 1, 3, 1); |
85 |
| - var actual = new DateTime(2011, 9, 13, 18, 22, 0); |
86 |
| - |
87 |
| - var ex = Record.Exception(() => Assert.Equivalent(expected, actual)); |
88 |
| - |
89 |
| - Assert.IsType<EquivalentException>(ex); |
90 |
| - Assert.Equal( |
91 |
| - "Assert.Equivalent() Failure" + Environment.NewLine + |
92 |
| - "Expected: 2022-12-01T01:03:01.0000000" + Environment.NewLine + |
93 |
| - "Actual: 2011-09-13T18:22:00.0000000", |
94 |
| - ex.Message |
95 |
| - ); |
96 |
| - } |
97 |
| - |
98 |
| - [Fact] |
99 |
| - public void DateTimeOffset_Failure() |
100 |
| - { |
101 |
| - var expected = new DateTimeOffset(2022, 12, 1, 1, 3, 1, TimeSpan.Zero); |
102 |
| - var actual = new DateTimeOffset(2011, 9, 13, 18, 22, 0, TimeSpan.Zero); |
103 |
| - |
104 |
| - var ex = Record.Exception(() => Assert.Equivalent(expected, actual)); |
105 |
| - |
106 |
| - Assert.IsType<EquivalentException>(ex); |
107 |
| - Assert.Equal( |
108 |
| - "Assert.Equivalent() Failure" + Environment.NewLine + |
109 |
| - "Expected: 2022-12-01T01:03:01.0000000+00:00" + Environment.NewLine + |
110 |
| - "Actual: 2011-09-13T18:22:00.0000000+00:00", |
111 |
| - ex.Message |
112 |
| - ); |
113 |
| - } |
114 |
| - |
115 |
| - [Fact] |
116 |
| - public void DateTimeToString_Failure() |
117 |
| - { |
118 |
| - var expected = new DateTime(2022, 12, 1, 1, 3, 1); |
119 |
| - var actual = "2022-12-01T01:03:01.0000000"; |
120 |
| - |
121 |
| - var ex = Record.Exception(() => Assert.Equivalent(expected, actual)); |
122 |
| - |
123 |
| - Assert.IsType<EquivalentException>(ex); |
124 |
| - Assert.Equal( |
125 |
| - "Assert.Equivalent() Failure" + Environment.NewLine + |
126 |
| - "Expected: 2022-12-01T01:03:01.0000000" + Environment.NewLine + |
127 |
| - "Actual: \"2022-12-01T01:03:01.0000000\"", |
128 |
| - ex.Message |
129 |
| - ); |
130 |
| - Assert.IsType<ArgumentException>(ex.InnerException); // Thrown by DateTime.CompareTo |
131 |
| - } |
132 |
| - |
133 | 55 | [Fact]
|
134 | 56 | public void SameType_Failure()
|
135 | 57 | {
|
@@ -1470,6 +1392,148 @@ public void Failure_Value()
|
1470 | 1392 | }
|
1471 | 1393 | }
|
1472 | 1394 |
|
| 1395 | + public class SpecialCases |
| 1396 | + { |
| 1397 | + // DateTime |
| 1398 | + |
| 1399 | + [Fact] |
| 1400 | + public void DateTime_Success() |
| 1401 | + { |
| 1402 | + var expected = new DateTime(2022, 12, 1, 1, 3, 1); |
| 1403 | + var actual = new DateTime(2022, 12, 1, 1, 3, 1); |
| 1404 | + |
| 1405 | + Assert.Equivalent(expected, actual); |
| 1406 | + } |
| 1407 | + |
| 1408 | + [Fact] |
| 1409 | + public void DateTime_Failure() |
| 1410 | + { |
| 1411 | + var expected = new DateTime(2022, 12, 1, 1, 3, 1); |
| 1412 | + var actual = new DateTime(2011, 9, 13, 18, 22, 0); |
| 1413 | + |
| 1414 | + var ex = Record.Exception(() => Assert.Equivalent(expected, actual)); |
| 1415 | + |
| 1416 | + Assert.IsType<EquivalentException>(ex); |
| 1417 | + Assert.Equal( |
| 1418 | + "Assert.Equivalent() Failure" + Environment.NewLine + |
| 1419 | + "Expected: 2022-12-01T01:03:01.0000000" + Environment.NewLine + |
| 1420 | + "Actual: 2011-09-13T18:22:00.0000000", |
| 1421 | + ex.Message |
| 1422 | + ); |
| 1423 | + } |
| 1424 | + |
| 1425 | + [Fact] |
| 1426 | + public void DateTimeToString_Failure() |
| 1427 | + { |
| 1428 | + var expected = new DateTime(2022, 12, 1, 1, 3, 1); |
| 1429 | + var actual = "2022-12-01T01:03:01.0000000"; |
| 1430 | + |
| 1431 | + var ex = Record.Exception(() => Assert.Equivalent(expected, actual)); |
| 1432 | + |
| 1433 | + Assert.IsType<EquivalentException>(ex); |
| 1434 | + Assert.Equal( |
| 1435 | + "Assert.Equivalent() Failure" + Environment.NewLine + |
| 1436 | + "Expected: 2022-12-01T01:03:01.0000000" + Environment.NewLine + |
| 1437 | + "Actual: \"2022-12-01T01:03:01.0000000\"", |
| 1438 | + ex.Message |
| 1439 | + ); |
| 1440 | + Assert.IsType<ArgumentException>(ex.InnerException); // Thrown by DateTime.CompareTo |
| 1441 | + } |
| 1442 | + |
| 1443 | + [Fact] |
| 1444 | + public void StringToDateTime_Success() |
| 1445 | + { |
| 1446 | + var expected = "2022-12-01T01:03:01.0000000"; |
| 1447 | + var actual = new DateTime(2022, 12, 1, 1, 3, 1); |
| 1448 | + |
| 1449 | + Assert.Equivalent(expected, actual); |
| 1450 | + } |
| 1451 | + |
| 1452 | + // DateTimeOffset |
| 1453 | + |
| 1454 | + [Fact] |
| 1455 | + public void DateTimeOffset_Success() |
| 1456 | + { |
| 1457 | + var expected = new DateTimeOffset(2022, 12, 1, 1, 3, 1, TimeSpan.Zero); |
| 1458 | + var actual = new DateTimeOffset(2022, 12, 1, 1, 3, 1, TimeSpan.Zero); |
| 1459 | + |
| 1460 | + Assert.Equivalent(expected, actual); |
| 1461 | + } |
| 1462 | + |
| 1463 | + [Fact] |
| 1464 | + public void DateTimeOffset_Failure() |
| 1465 | + { |
| 1466 | + var expected = new DateTimeOffset(2022, 12, 1, 1, 3, 1, TimeSpan.Zero); |
| 1467 | + var actual = new DateTimeOffset(2011, 9, 13, 18, 22, 0, TimeSpan.Zero); |
| 1468 | + |
| 1469 | + var ex = Record.Exception(() => Assert.Equivalent(expected, actual)); |
| 1470 | + |
| 1471 | + Assert.IsType<EquivalentException>(ex); |
| 1472 | + Assert.Equal( |
| 1473 | + "Assert.Equivalent() Failure" + Environment.NewLine + |
| 1474 | + "Expected: 2022-12-01T01:03:01.0000000+00:00" + Environment.NewLine + |
| 1475 | + "Actual: 2011-09-13T18:22:00.0000000+00:00", |
| 1476 | + ex.Message |
| 1477 | + ); |
| 1478 | + } |
| 1479 | + |
| 1480 | + // DirectoryInfo |
| 1481 | + |
| 1482 | + [Fact] |
| 1483 | + public void DirectoryInfo_Success() |
| 1484 | + { |
| 1485 | + var assemblyPath = Path.GetDirectoryName(typeof(SpecialCases).Assembly.Location); |
| 1486 | + Assert.NotNull(assemblyPath); |
| 1487 | + |
| 1488 | + var expected = new DirectoryInfo(assemblyPath); |
| 1489 | + var actual = new DirectoryInfo(assemblyPath); |
| 1490 | + |
| 1491 | + Assert.Equivalent(expected, actual); |
| 1492 | + } |
| 1493 | + |
| 1494 | + [Fact] |
| 1495 | + public void DirectoryInfo_Failure() |
| 1496 | + { |
| 1497 | + var assemblyPath = Path.GetDirectoryName(typeof(SpecialCases).Assembly.Location); |
| 1498 | + Assert.NotNull(assemblyPath); |
| 1499 | + var assemblyParentPath = Path.GetDirectoryName(assemblyPath); |
| 1500 | + Assert.NotNull(assemblyParentPath); |
| 1501 | + Assert.NotEqual(assemblyPath, assemblyParentPath); |
| 1502 | + |
| 1503 | + var expected = new FileInfo(assemblyPath); |
| 1504 | + var actual = new FileInfo(assemblyParentPath); |
| 1505 | + |
| 1506 | + var ex = Record.Exception(() => Assert.Equivalent(expected, actual)); |
| 1507 | + |
| 1508 | + Assert.IsType<EquivalentException>(ex); |
| 1509 | + Assert.StartsWith("Assert.Equivalent() Failure: Mismatched value on member 'FullName'" + Environment.NewLine, ex.Message); |
| 1510 | + } |
| 1511 | + |
| 1512 | + // FileInfo |
| 1513 | + |
| 1514 | + [Fact] |
| 1515 | + public void FileInfo_Success() |
| 1516 | + { |
| 1517 | + var assembly = typeof(SpecialCases).Assembly.Location; |
| 1518 | + var expected = new FileInfo(assembly); |
| 1519 | + var actual = new FileInfo(assembly); |
| 1520 | + |
| 1521 | + Assert.Equivalent(expected, actual); |
| 1522 | + } |
| 1523 | + |
| 1524 | + [Fact] |
| 1525 | + public void FileInfo_Failure() |
| 1526 | + { |
| 1527 | + var expected = new FileInfo(typeof(SpecialCases).Assembly.Location); |
| 1528 | + var actual = new FileInfo(typeof(Assert).Assembly.Location); |
| 1529 | + |
| 1530 | + var ex = Record.Exception(() => Assert.Equivalent(expected, actual)); |
| 1531 | + |
| 1532 | + Assert.IsType<EquivalentException>(ex); |
| 1533 | + Assert.StartsWith("Assert.Equivalent() Failure: Mismatched value on member 'FullName'" + Environment.NewLine, ex.Message); |
| 1534 | + } |
| 1535 | + } |
| 1536 | + |
1473 | 1537 | public class CircularReferences
|
1474 | 1538 | {
|
1475 | 1539 | [Fact]
|
|
0 commit comments