Exemple #1
0
        public void Emitting_MsgOp_Should_continue_Emitting_When_using_delegate_without_error_handler_but_failing_observer_gets_discarded()
        {
            var msgOp  = MsgOp.CreateMsg("TestSubject", "e8fb57beeb094bbfb545056057a8f7f2", ReadOnlySpan <char> .Empty, new byte[0]);
            var countA = 0;
            var countB = 0;
            var countC = 0;

            UnitUnderTest.MsgOpsStream.Subscribe(op =>
            {
                if (countA == 0)
                {
                    countA += 1;
                    throw new Exception("Fail");
                }

                countA += 1;
            });
            UnitUnderTest.MsgOpsStream.Subscribe(op => countB += 1);
            UnitUnderTest.MsgOpsStream.Subscribe(op => countC += 1);

            UnitUnderTest.Emit(msgOp);
            UnitUnderTest.Emit(msgOp);

            countA.Should().Be(1);
            countB.Should().Be(2);
            countC.Should().Be(2);
        }
Exemple #2
0
        public void Emitting_MsgOp_Should_continue_Emitting_When_using_delegate_with_error_handler_but_failing_observer_gets_discarded()
        {
            var       msgOp     = MsgOp.CreateMsg("TestSubject", "01c549bed5f643e484c2841aff7a0d9d", ReadOnlySpan <char> .Empty, new byte[0]);
            var       countA    = 0;
            var       countB    = 0;
            var       countC    = 0;
            var       exToThrow = new Exception(Guid.NewGuid().ToString());
            Exception caughtEx  = null;

            UnitUnderTest.MsgOpsStream.Subscribe(op =>
            {
                if (countA == 0)
                {
                    countA += 1;
                    throw exToThrow;
                }

                countA += 1;
            }, ex => caughtEx = ex);
            UnitUnderTest.MsgOpsStream.Subscribe(op => countB += 1);
            UnitUnderTest.MsgOpsStream.Subscribe(op => countC += 1);

            UnitUnderTest.Emit(msgOp);
            UnitUnderTest.Emit(msgOp);

            caughtEx.Should().BeNull();
            countA.Should().Be(1);
            countB.Should().Be(2);
            countC.Should().Be(2);
        }
        public void Should_be_able_to_apply_predicate()
        {
            var observer1 = new Mock <IObserver <Data> >();
            var observer2 = new Mock <IObserver <Data> >();

            UnitUnderTest.Where(d => d.Value <= 2).Subscribe(observer1.Object);
            UnitUnderTest.Where(d => d.Value >= 2).Subscribe(observer2.Object);

            UnitUnderTest.Emit(new Data {
                Value = 1
            });
            UnitUnderTest.Emit(new Data {
                Value = 2
            });
            UnitUnderTest.Emit(new Data {
                Value = 3
            });

            observer1.Verify(f => f.OnNext(It.IsAny <Data>()), Times.Exactly(2));
            observer1.Verify(f => f.OnNext(It.Is <Data>(d => d.Value == 1)), Times.Once);
            observer1.Verify(f => f.OnNext(It.Is <Data>(d => d.Value == 2)), Times.Once);

            observer2.Verify(f => f.OnNext(It.IsAny <Data>()), Times.Exactly(2));
            observer2.Verify(f => f.OnNext(It.Is <Data>(d => d.Value == 2)), Times.Once);
            observer2.Verify(f => f.OnNext(It.Is <Data>(d => d.Value == 3)), Times.Once);
        }
Exemple #4
0
        public void Emitting_non_MsgOp_Should_continue_Emitting_When_using_delegate_without_error_handler_but_failing_observer_gets_discarded()
        {
            var countA = 0;
            var countB = 0;
            var countC = 0;

            UnitUnderTest.AllOpsStream.Subscribe(op =>
            {
                if (countA == 0)
                {
                    countA += 1;
                    throw new Exception("Fail");
                }

                countA += 1;
            });
            UnitUnderTest.AllOpsStream.Subscribe(op => countB += 1);
            UnitUnderTest.AllOpsStream.Subscribe(op => countC += 1);

            UnitUnderTest.Emit(PingOp.Instance);
            UnitUnderTest.Emit(PingOp.Instance);

            countA.Should().Be(1);
            countB.Should().Be(2);
            countC.Should().Be(2);
        }
Exemple #5
0
        public void Emitting_MsgOp_Should_continue_Emitting_When_using_observer_with_error_handler_but_failing_observer_gets_discarded()
        {
            var       msgOp     = MsgOp.CreateMsg("TestSubject", "f0dd86b9c2804632919b7b78292435e6", ReadOnlySpan <char> .Empty, new byte[0]);
            var       countA    = 0;
            var       countB    = 0;
            var       countC    = 0;
            var       exToThrow = new Exception(Guid.NewGuid().ToString());
            Exception caughtEx  = null;

            UnitUnderTest.MsgOpsStream.Subscribe(NatsObserver.Delegating <IOp>(op =>
            {
                if (countA == 0)
                {
                    countA += 1;
                    throw exToThrow;
                }

                countA += 1;
            }, ex => caughtEx = ex));
            UnitUnderTest.MsgOpsStream.Subscribe(NatsObserver.Delegating <IOp>(op => countB += 1));
            UnitUnderTest.MsgOpsStream.Subscribe(NatsObserver.Delegating <IOp>(op => countC += 1));

            UnitUnderTest.Emit(msgOp);
            UnitUnderTest.Emit(msgOp);

            caughtEx.Should().BeNull();
            countA.Should().Be(1);
            countB.Should().Be(2);
            countC.Should().Be(2);
        }
Exemple #6
0
        public void Should_be_able_to_reconfigure_using_generics_type()
        {
            var item = new MyType
            {
                MyInt    = 42,
                MyString = "Foo"
            };

            var structure = UnitUnderTest.CreateStructure(item);

            structure.Name.Should().Be(nameof(MyType));
            structure.Indexes.Should().HaveCount(2);
            structure.Indexes.Should()
            .Contain(i => i.Name == nameof(item.MyInt))
            .Which.Value.Should().Be(item.MyInt);
            structure.Indexes.Should()
            .Contain(i => i.Name == nameof(item.MyString))
            .Which.Value.Should().Be(item.MyString);

            UnitUnderTest.Configure <MyType>(cfg => cfg.Members("MyInt").UsingIndexMode(IndexMode.Inclusive));

            structure = UnitUnderTest.CreateStructure(item);
            structure.Name.Should().Be(nameof(MyType));
            structure.Indexes.Should().HaveCount(1);
            structure.Indexes.Should()
            .Contain(i => i.Name == nameof(item.MyInt))
            .Which.Value.Should().Be(item.MyInt);
        }
Exemple #7
0
 public void AACreatesAnInstance()
 {
     UnitUnderTest
     .ShouldNotBeNull()
     .ShouldBeAssignableTo <ClassWith3ConstructorParams <INterfaceWithClassInSameAssembly,
                                                         INterfaceWithFakeInTestAssembly, INterfaceWithClassInNotReferencedAssembly> >();
 }
Exemple #8
0
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            lstStatus.Items.Add("Process Started");

            //System.IO.FileInfo xmlFile = new System.IO.FileInfo(@"C:\work\Josh\Xml\6963A_123456_25Apr2019T1551_xCert.xml");
            //UnitUnderTest unit = XmlParser.LoadUnitUnderTest(@"C:\work\Josh\Xml\6963A_123456_25Apr2019T1551_xCert.xml");

            DirectoryInfo sourceDirectory = new DirectoryInfo(txtSource.Text);

            System.IO.FileInfo[] xmlFiles = sourceDirectory.GetFiles("*.xml");


            foreach (System.IO.FileInfo xmlFile in xmlFiles)
            {
                lstStatus.Items.Add($"Found {xmlFile.Name} file.");
                UnitUnderTest unit = XmlParser.LoadUnitUnderTest(xmlFile.FullName);
                lstStatus.Items.Add($"Loaded contents of the {xmlFile.Name} file.");

                System.IO.FileInfo pdfFile = new System.IO.FileInfo($@"{txtDestination.Text}\\{xmlFile.Name.Replace("xml", "pdf")}");
                PdfGenerator.GeneratePdf(unit, pdfFile.FullName, Decimal.ToInt32(txtFrom.Value), Decimal.ToInt32(txtIncrement.Value));
                lstStatus.Items.Add($"Generated {pdfFile.Name} file.");
                System.Diagnostics.Process.Start(pdfFile.FullName);
            }


            Properties.Settings.Default.PressureFrom      = Decimal.ToInt32(this.txtFrom.Value);
            Properties.Settings.Default.PressureIncrement = Decimal.ToInt32(this.txtIncrement.Value);
            Properties.Settings.Default.Save();
            lstStatus.Items.Add($"Saved defaults.");
            //System.Diagnostics.Process.Start(pdfFile.FullName);
            //Application.Exit();
        }
 public void UUTShouldNotBeNull()
 {
     try
     {
         UnitUnderTest.ShouldNotBeNull();
         Console.WriteLine("----------------");
         foreach (var kv in Activator.LastActivationTree)
         {
             Console.WriteLine(kv.ToString(null));
         }
         Console.WriteLine("----------------");
         foreach (var kv in Activator.LastErrorList)
         {
             Console.WriteLine(kv.Key.ToString(ActivationInfoFormat.TypeName) + " :: " + kv.Value);
         }
         Console.WriteLine("----------------");
     } catch (Exception)
     {
         Console.WriteLine("----------------");
         foreach (var kv in Activator.LastErrorList)
         {
             Console.WriteLine(kv.Key.ToString(ActivationInfoFormat.TypeName) + " :: " + kv.Value);
         }
         Console.WriteLine("----------------");
         foreach (var kv in Activator.LastActivationTree)
         {
             Console.WriteLine(kv.ToString(null));
         }
         Console.WriteLine("----------------");
         throw;
     }
 }
        public void Is_initialized_properly()
        {
            UnitUnderTest = PongOp.Instance;

            UnitUnderTest.Marker.Should().Be("PONG");
            UnitUnderTest.ToString().Should().Be("PONG");
        }
Exemple #11
0
        public void Emitting_non_MsgOp_Should_continue_Emitting_When_using_delegate_with_error_handler_but_failing_observer_gets_discarded()
        {
            var       countA    = 0;
            var       countB    = 0;
            var       countC    = 0;
            var       exToThrow = new Exception(Guid.NewGuid().ToString());
            Exception caughtEx  = null;

            UnitUnderTest.AllOpsStream.Subscribe(op =>
            {
                if (countA == 0)
                {
                    countA += 1;
                    throw exToThrow;
                }

                countA += 1;
            }, ex => caughtEx = ex);
            UnitUnderTest.AllOpsStream.Subscribe(op => countB += 1);
            UnitUnderTest.AllOpsStream.Subscribe(op => countC += 1);

            UnitUnderTest.Emit(PingOp.Instance);
            UnitUnderTest.Emit(PingOp.Instance);

            caughtEx.Should().BeNull();
            countA.Should().Be(1);
            countB.Should().Be(2);
            countC.Should().Be(2);
        }
Exemple #12
0
        public void Emitting_MsgOp_Should_continue_Emitting_When_using_observer_without_error_handler_but_failing_observer_gets_discarded()
        {
            var msgOp  = MsgOp.CreateMsg("TestSubject", "60a152d4b5804b23abe088eeac63b55e", ReadOnlySpan <char> .Empty, new byte[0]);
            var countA = 0;
            var countB = 0;
            var countC = 0;

            UnitUnderTest.MsgOpsStream.Subscribe(NatsObserver.Delegating <IOp>(op =>
            {
                if (countA == 0)
                {
                    countA += 1;
                    throw new Exception("Fail");
                }

                countA += 1;
            }));
            UnitUnderTest.MsgOpsStream.Subscribe(NatsObserver.Delegating <IOp>(op => countB += 1));
            UnitUnderTest.MsgOpsStream.Subscribe(NatsObserver.Delegating <IOp>(op => countC += 1));

            UnitUnderTest.Emit(msgOp);
            UnitUnderTest.Emit(msgOp);

            countA.Should().Be(1);
            countB.Should().Be(2);
            countC.Should().Be(2);
        }
Exemple #13
0
        private static void ParseMeasureData(UnitUnderTest unit, XDocument document)
        {
            var data = (from dt in document.Descendants("MeasureData") select dt);

            foreach (var dt in data)
            {
                var md = new MeasureData()
                {
                    Id = int.Parse(dt.Element("Id").Value)
                };

                var channels = (from ch in dt.Descendants("Channel") select ch);

                foreach (var ch in channels)
                {
                    var channel = new Channel()
                    {
                        Name = ch.Element("Name").Value,
                        Unit = ch.Element("Unit").Value,
                        Data = ch.Element("Data").Value
                    };

                    channel.Attributes = (from attr in ch.Descendants("Attribute")
                                          select new Domain.Attribute()
                    {
                        Key = attr.Element("Key").Value,
                        Value = attr.Element("Value").Value
                    }).ToList();
                    md.Channels.Add(channel);
                }

                unit.MeasureDatas.Add(md);
            }
        }
Exemple #14
0
        public void AAFindsConcreteTypeForInterfaceInNamedAssembly()
        {
            UnitUnderTest.ShouldNotBeNull();

            UnitUnderTest.ShouldBeAssignableTo <ClassWith1ConstructorParam <INterfaceWithFakeInTestAssembly> >();
            typeof(NterfaceWithFakeInTestAssembly).ShouldBe(UnitUnderTest.Param1.GetType());
        }
        public async Task Should_be_able_to_pass_envelope_state()
        {
            var interceptionsFromMiddlewares = new List <string>();

            UnitUnderTest.Use(next => async envelope =>
            {
                envelope.SetState("MW1", $"MW1 of {envelope.MessageType.Name}");
                await next(envelope).ConfigureAwait(false);
                interceptionsFromMiddlewares.Add($"MW2 in MW1 is '{envelope.GetState("MW2")}'");
            });
            UnitUnderTest.Use(next => async envelope =>
            {
                interceptionsFromMiddlewares.Add($"MW1 in MW2 is '{envelope.GetState("MW1")}'");
                envelope.SetState("MW2", $"MW2 of {envelope.MessageType.Name}");
                await next(envelope).ConfigureAwait(false);
            });

            await UnitUnderTest.RouteAsync(new ConcreteMessageA());

            await UnitUnderTest.RouteAsync(new ConcreteMessageB());

            interceptionsFromMiddlewares.Should().ContainInOrder(
                "MW1 in MW2 is 'MW1 of ConcreteMessageA'",
                "MW2 in MW1 is 'MW2 of ConcreteMessageA'",
                "MW1 in MW2 is 'MW1 of ConcreteMessageB'",
                "MW2 in MW1 is 'MW2 of ConcreteMessageB'");
        }
        public async Task Should_invoke_middlewares_When_more_then_one_middleware_exists()
        {
            var interceptionsFromMiddlewares = new List <string>();

            UnitUnderTest.Use(next => async envelope =>
            {
                interceptionsFromMiddlewares.Add($"MW1 Begin {envelope.MessageType.Name}");
                await next(envelope).ConfigureAwait(false);
                interceptionsFromMiddlewares.Add($"MW1 End {envelope.MessageType.Name}");
            });

            UnitUnderTest.Use(next => async envelope =>
            {
                interceptionsFromMiddlewares.Add($"MW2 Begin {envelope.MessageType.Name}");
                await next(envelope).ConfigureAwait(false);
                interceptionsFromMiddlewares.Add($"MW2 End {envelope.MessageType.Name}");
            });

            await UnitUnderTest.RouteAsync(new ConcreteMessageA());

            await UnitUnderTest.RouteAsync(new ConcreteMessageB());

            interceptionsFromMiddlewares.Should().ContainInOrder(
                "MW1 Begin ConcreteMessageA",
                "MW2 Begin ConcreteMessageA",
                "MW2 End ConcreteMessageA",
                "MW1 End ConcreteMessageA",
                "MW1 Begin ConcreteMessageB",
                "MW2 Begin ConcreteMessageB",
                "MW2 End ConcreteMessageB",
                "MW1 End ConcreteMessageB");
        }
Exemple #17
0
        public void Should_be_able_to_reconfigure_using_anonymous_type()
        {
            var item = new
            {
                MyInt    = 42,
                MyString = "Foo"
            };

            var structure = UnitUnderTest.CreateStructure(item);

            structure.Name.Should().Contain("Anonymous");
            structure.Indexes.Should().HaveCount(2);
            structure.Indexes.Should()
            .Contain(i => i.Name == nameof(item.MyInt))
            .Which.Value.Should().Be(item.MyInt);
            structure.Indexes.Should()
            .Contain(i => i.Name == nameof(item.MyString))
            .Which.Value.Should().Be(item.MyString);

            UnitUnderTest.ConfigureUsingTemplate(item, cfg => cfg.Members(i => i.MyInt).UsingIndexMode(IndexMode.Inclusive));

            structure = UnitUnderTest.CreateStructure(item);
            structure.Name.Should().Contain("Anonymous");
            structure.Indexes.Should().HaveCount(1);
            structure.Indexes.Should()
            .Contain(i => i.Name == nameof(item.MyInt))
            .Which.Value.Should().Be(item.MyInt);
        }
        public void KnownMessageTypes_Should_yield_message_types_When_routes_has_been_added()
        {
            var route = CreateMessageRoute <ConcreteMessageA>();

            UnitUnderTest.Add(route);

            UnitUnderTest.KnownMessageTypes.Should().Contain(route.MessageType);
        }
        public void Add_of_single_Should_add()
        {
            var route = CreateMessageRoute <ConcreteMessageA>();

            UnitUnderTest.Add(route);

            UnitUnderTest.Should().Contain(route);
        }
        public void HasRoute_Should_return_false_When_no_route_exist_for_message_type()
        {
            var route = CreateMessageRoute <ConcreteMessageA>();

            UnitUnderTest.Add(route);

            UnitUnderTest.HasRoute(typeof(ConcreteMessageB)).Should().BeFalse();
        }
        public void Indexer_Should_yield_route_by_message_type_When_route_for_it_exists()
        {
            var route = CreateMessageRoute <ConcreteMessageA>();

            UnitUnderTest.Add(route);

            UnitUnderTest[route.MessageType].Should().Be(route);
        }
        public void GetRoute_Should_return_route_When_route_exist_for_message_type()
        {
            var route = CreateMessageRoute <ConcreteMessageA>();

            UnitUnderTest.Add(route);

            UnitUnderTest.GetRoute(route.MessageType).Should().Be(route);
        }
        public void UUTreturnsDataFromDbQuerySingleColumn()
        {
            var dbData = new[] { "row1", "row2", "row3", "row4" };

            Db.SetUpForQuerySingleColumn(dbData);

            UnitUnderTest.FromDbStrings().ShouldEqualByValue(dbData);
        }
        public void Should_create_two_routes_with_two_actions_each_When_two_interface_message_handlers_in_two_classes_exists()
        {
            var routes = UnitUnderTest.Create(GetType().Assembly, typeof(IHandleForCaseB <>));

            routes.Should().HaveCount(2);
            routes.Single(r => r.MessageType == typeof(INonConcreteMessageA)).Actions.Should().HaveCount(2);
            routes.Single(r => r.MessageType == typeof(INonConcreteMessageB)).Actions.Should().HaveCount(2);
        }
        public void Add_of_single_Should_not_add_When_same_route_is_added_twice()
        {
            var route = CreateMessageRoute <ConcreteMessageA>();

            UnitUnderTest.Add(route);
            UnitUnderTest.Add(route);

            UnitUnderTest.Should().HaveCount(1);
        }
Exemple #26
0
        public void ON_GetEdgeData_WHEN_Src_Vertex_Index_Out_Of_Range_SHOULD_Throw_IndexOutOfRangeException()
        {
            // Arrange
            var uut = new UnitUnderTest <int>(index => _vertexMocks[index].Object, () => _vertexMocks.Length);

            // Act
            uut.GetEdgeData(-1, 1);

            // Assert handled by ExpectedException
        }
Exemple #27
0
        public void TestPrivates()
        {
            var uut           = new UnitUnderTest();
            var privateObject = new PrivateObject(uut);

            Assert.AreEqual(42, privateObject.GetField("myPrivateParts"));

            privateObject.SetField("myPrivateParts", 23);
            Assert.AreEqual(23, uut.ThePublicValue);
        }
        public void Add_of_single_Should_add_When_two_routes_with_different_message_type_are_added()
        {
            var routeA = CreateMessageRoute <ConcreteMessageA>();
            var routeB = CreateMessageRoute <ConcreteMessageB>();

            UnitUnderTest.Add(routeA);
            UnitUnderTest.Add(routeB);

            UnitUnderTest.Should().HaveCount(2);
        }
 public void AndBuildsRequestedType()
 {
     UnitUnderTest.ShouldNotBeNull();
     UnitUnderTest.ShouldBeAssignableTo
     <ClassWith4ConstructorParams
      <INterfaceWithClassInSameAssembly,
       INterfaceWithFakeInTestAssembly,
       INterfaceWithClassInNotReferencedAssembly,
       ICloneable> >();
 }
        public void Emitting_Should_invoke_logger_for_error_When_exception_is_thrown()
        {
            var thrown = new Exception("I FAILED!");

            UnitUnderTest.Subscribe(msg => throw thrown);

            UnitUnderTest.Emit(Mock.Of <Data>());

            FakeLogger.Verify(f => f.Error(It.Is <string>(m => m.Contains("Error in observer while emitting value.")), thrown), Times.Once);
        }