public void Should_succeed_when_asserting_non_empty_guid_is_not_empty() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var guid = new Guid("12345678-1234-1234-1234-123456789012"); //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => guid.Should().NotBeEmpty(); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldNotThrow(); }
public void Should_fail_when_asserting_non_empty_guid_is_empty() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var guid = new Guid("12345678-1234-1234-1234-123456789012"); //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => guid.Should().BeEmpty("because we want to test the failure {0}", "message"); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldThrow<AssertFailedException>().WithMessage( "Expected empty Guid because we want to test the failure message, but found {12345678-1234-1234-1234-123456789012}."); }
public void Should_fail_when_asserting_guid_equals_a_different_guid() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var guid = new Guid("11111111-aaaa-bbbb-cccc-999999999999"); var differentGuid = new Guid("55555555-ffff-eeee-dddd-444444444444"); //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => guid.Should().Be(differentGuid, "because we want to test the failure {0}", "message"); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldThrow<AssertFailedException>().WithMessage( "Expected Guid to be {55555555-ffff-eeee-dddd-444444444444} because we want to test the failure message, but found {11111111-aaaa-bbbb-cccc-999999999999}."); }
public void Should_fail_with_descriptive_message_when_asserting_nullable_guid_value_with_a_value_to_be_null() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- Guid? nullableGuid = new Guid("11111111-aaaa-bbbb-cccc-999999999999"); //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => nullableGuid.Should().NotHaveValue("because we want to test the failure {0}", "message"); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldThrow<AssertFailedException>() .WithMessage("Did not expect a value because we want to test the failure message, but found {11111111-aaaa-bbbb-cccc-999999999999}."); }
public void FullTestLikeZeroMqZyre() { var node1Writer = new ConsoleLogger("node1"); var node2Writer = new ConsoleLogger("node2"); // Create two nodes using (var node1 = new Zyre("node1", false, node1Writer.ConsoleWrite)) using (var node2 = new Zyre("node2", false, node2Writer.ConsoleWrite)) { int major, minor, patch; node1.Version(out major, out minor, out patch); major.Should().Be(Zyre.ZyreVersionMajor); node1.Should().NotBeNull(); node1.Name().Should().Be("node1"); node1.SetHeader("X-HELLO", "World"); // Start both nodes node1.Start(); var uuid1 = node1.Uuid(); uuid1.Should().NotBeEmpty(); node1Writer.ConsoleWrite("After starting node1, Dump():"); node1.Dump(); node2.Should().NotBeNull(); node2.Name().Should().Be("node2"); node2.Start(); var uuid2 = node2.Uuid(); uuid1.Should().NotBe(uuid2); Console.WriteLine("After starting node2, Dump():"); node2.Dump(); // Give time for them to interconnect. Our default is beacons every second Thread.Sleep(1100); Console.WriteLine("After Thread.Sleep(1100):"); Console.WriteLine("node1 Joining Global"); node1.Join("GLOBAL"); Console.WriteLine("node2 Joining Global"); node2.Join("GLOBAL"); node1.Dump(); node2.Dump(); var node1Peers = node1.Peers(); node1Peers.Count.Should().Be(1); Console.WriteLine("node1 Joining node1 group of one"); node1.Join("node1 group of one"); Console.WriteLine("node2 Joining node1 group of one"); node2.Join("node2 group of one"); // Give them time to join their groups Thread.Sleep(100); Console.WriteLine("After 2nd Thread.Sleep(100):"); node1.Dump(); node2.Dump(); var peerGroups = node1.PeerGroups(); peerGroups.Count.Should().Be(2); var node2Peers = node2.Peers(); node2Peers.Count.Should().Be(1); var value = node2.PeerHeaderValue(uuid1, "X-HELLO"); value.Should().Be("World"); // One node shouts to GLOBAL Console.WriteLine("node1 Shouting to Global"); node1.Shouts("GLOBAL", "Hello, World"); // Second node should receive ENTER, JOIN, JOIN and SHOUT var msg = node2.Receive(); msg.Should().NotBeNull(); var command = msg.Pop().ConvertToString(); command.Should().Be("ENTER"); msg.FrameCount.Should().Be(4); var peerIdBytes = msg.Pop().Buffer; var peerId = new Guid(peerIdBytes); peerId.Should().Be(uuid1); var name = msg.Pop().ConvertToString(); name.Should().Be("node1"); var headersBuffer = msg.Pop().Buffer; var headers = Serialization.BinaryDeserialize<Dictionary<string, string>>(headersBuffer); var address = msg.Pop().ConvertToString(); headers.Count.Should().Be(1); headers["X-HELLO"].Should().Be("World"); address.Should().NotBeNullOrEmpty(); msg = node2.Receive(); msg.Should().NotBeNull(); command = msg.Pop().ConvertToString(); command.Should().Be("JOIN"); msg.FrameCount.Should().Be(3); msg = node2.Receive(); msg.Should().NotBeNull(); command = msg.Pop().ConvertToString(); command.Should().Be("JOIN"); msg.FrameCount.Should().Be(3); msg = node2.Receive(); msg.Should().NotBeNull(); command = msg.Pop().ConvertToString(); command.Should().Be("SHOUT"); Console.WriteLine("Stopping node2"); node2.Stop(); msg = node2.Receive(); msg.Should().NotBeNull(); command = msg.Pop().ConvertToString(); command.Should().Be("STOP"); Console.WriteLine("Stopping node1"); node1.Stop(); Thread.Sleep(100); Console.WriteLine("After Stopping both:"); node1.Dump(); node2.Dump(); Console.WriteLine("OK"); } }
public void Should_succeed_when_asserting_guid_equals_the_same_guid() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var guid = new Guid("11111111-aaaa-bbbb-cccc-999999999999"); var sameGuid = new Guid("11111111-aaaa-bbbb-cccc-999999999999"); //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => guid.Should().Be(sameGuid); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldNotThrow(); }
public void Should_succeed_when_asserting_guid_does_not_equal_the_same_guid() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var guid = new Guid("11111111-aaaa-bbbb-cccc-999999999999"); var sameGuid = new Guid("11111111-aaaa-bbbb-cccc-999999999999"); //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => guid.Should().NotBe(sameGuid, "because we want to test the failure {0}", "message"); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldThrow<AssertFailedException>().WithMessage( "Did not expect Guid to be {11111111-aaaa-bbbb-cccc-999999999999} because we want to test the failure message."); }
public void Should_succeed_when_asserting_guid_does_not_equal_a_different_guid() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var guid = new Guid("11111111-aaaa-bbbb-cccc-999999999999"); var differentGuid = new Guid("55555555-ffff-eeee-dddd-444444444444"); //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => guid.Should().NotBe(differentGuid); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldNotThrow(); }
private static void AssertTestResult(XmlDocument xmlDocument, CasperJsTest test, string outcomeText, int numTest) { Guid testEntryGuid = new Guid(); Guid.TryParse(xmlDocument.ChildNodes[1].ChildNodes[3].ChildNodes[numTest].Attributes["testId"].Value, out testEntryGuid) .Should() .BeTrue(); testEntryGuid.Should().Be(test.Id); Guid testExecutionIdGuid = new Guid(); Guid.TryParse(xmlDocument.ChildNodes[1].ChildNodes[3].ChildNodes[numTest].Attributes["executionId"].Value, out testExecutionIdGuid) .Should() .BeTrue(); testExecutionIdGuid.Should().Be(test.ExecutionId); xmlDocument.ChildNodes[1].ChildNodes[3].ChildNodes[numTest].Attributes["testName"].Value.Should().Be(test.Name); xmlDocument.ChildNodes[1].ChildNodes[3].ChildNodes[numTest].Attributes["duration"].Value.Should() .Be("00:00:00.4590000"); xmlDocument.ChildNodes[1].ChildNodes[3].ChildNodes[numTest].Attributes["outcome"].Value.Should().Be(outcomeText); Guid testTypeIdGuid = new Guid(); Guid.TryParse(xmlDocument.ChildNodes[1].ChildNodes[3].ChildNodes[numTest].Attributes["testType"].Value, out testTypeIdGuid) .Should() .BeTrue(); Guid testListIdGuid = new Guid(); Guid.TryParse(xmlDocument.ChildNodes[1].ChildNodes[3].ChildNodes[0].Attributes["testListId"].Value, out testListIdGuid) .Should() .BeTrue(); }
public void ShouldCreateTwoTestEntryNodeIfThereIsTwoPassedTests() { var results = new CasperJsTestsResults(); results.PassedTests.Add(new CasperJsTest { Name = "test name 1" }); results.PassedTests.Add(new CasperJsTest { Name = "test name 2" }); string trx = CasperJsTrxCreator.Create(results); var xmlDocument = new XmlDocument(); xmlDocument.LoadXml(trx); Guid testDefinitionGuid = new Guid(); Guid.TryParse(xmlDocument.ChildNodes[1].ChildNodes[1].ChildNodes[0].Attributes["id"].Value, out testDefinitionGuid); Guid testEntryGuid = new Guid(); Guid.TryParse(xmlDocument.ChildNodes[1].ChildNodes[2].ChildNodes[0].Attributes["testId"].Value, out testEntryGuid) .Should() .BeTrue(); testDefinitionGuid.Should().Be(testEntryGuid); Guid testExecutionIdGuid = new Guid(); Guid.TryParse(xmlDocument.ChildNodes[1].ChildNodes[2].ChildNodes[1].Attributes["executionId"].Value, out testExecutionIdGuid) .Should() .BeTrue(); Guid.TryParse(xmlDocument.ChildNodes[1].ChildNodes[1].ChildNodes[1].Attributes["id"].Value, out testDefinitionGuid); Guid.TryParse(xmlDocument.ChildNodes[1].ChildNodes[2].ChildNodes[1].Attributes["testId"].Value, out testEntryGuid) .Should() .BeTrue(); testDefinitionGuid.Should().Be(testEntryGuid); Guid.TryParse(xmlDocument.ChildNodes[1].ChildNodes[2].ChildNodes[1].Attributes["executionId"].Value, out testExecutionIdGuid) .Should() .BeTrue(); }