Exemplo n.º 1
0
        public void DoIt()
        {
            var machine = new Machine(_stateFactory, _persister);

            machine.Configure(p => p
                 .Setup<StateA>(x => x.Reached5)
                 .Setup<StateA>(x => x.Reaced10)
                     .TransitionTo<StateB>()
                     .TransitionTo<StateC>());

            machine.Configure(p => p
                .Setup<StateB>(x => x.Reached15)
                .Setup<StateC>(x => x.Reached20)
                    .TransitionTo<StateD>());

            string descriptions = machine.GetDescriptions();

            var fooData = new FooData();
            fooData.Id = Guid.NewGuid();

            for (int i = 0; i < 50; i++)
            {
                machine.Process(fooData);
                App.Worker.Increase();
            }
        }
Exemplo n.º 2
0
        public void Process__bubbles_processed_dive_before_saving_dive()
        {
            var accessed = 0;

            var parserMock = new Mock<IImageParser>();
            var pixels = new[] { new Pixel(2, 3), new Pixel(3, 4), new Pixel(5, 4) };
            parserMock.Setup(d => d.ReadDocument()).Returns(pixels);

            var dives = new[] { new Dive(15, 50, 23, ""), new Dive(24, 20, 33, "") };
            var dr = new Mock<IDiveRepository>();
            dr.Setup(inp => inp.LoadDives()).Returns(dives);

            var sf = new Mock<ISampleFactory>();
            var processed = new[] { new ProcessedDive(dives[0]), new ProcessedDive(dives[0]) };
            sf.Setup(inp => inp.Create(It.IsAny<IEnumerable<Pixel>>(), dives[0])).Returns(processed[0]);
            sf.Setup(inp => inp.Create(It.IsAny<IEnumerable<Pixel>>(), dives[1])).Returns(processed[1]);

            Func<DlImageParsr.Model.Dive, IImageParser> facFunc = d => { return parserMock.Object; };

            var machine = new Machine(dr.Object, sf.Object, facFunc);
            machine.BeforeSavingDive += (dive) => accessed += dive.DiveLogId;
            machine.Process();

            accessed.Should().BeGreaterOrEqualTo(25);
        }
Exemplo n.º 3
0
        public void Process__disposes_the_image_parser()
        {
            var parserMock = new Mock<IImageParser>();
            var pixels = new[] { new Pixel(2, 3), new Pixel(3, 4), new Pixel(5, 4) };
            parserMock.Setup(d => d.ReadDocument()).Returns(pixels);

            var dives = new[] { new Dive(14, 50, 23, "")};
            var dr = new Mock<IDiveRepository>();
            dr.Setup(inp => inp.LoadDives()).Returns(dives);

            var sf = new Mock<ISampleFactory>();

            Func<DlImageParsr.Model.Dive, IImageParser> facFunc = d => { return parserMock.Object; };

            var machine = new Machine(dr.Object, sf.Object, facFunc);

            machine.Process();

            parserMock.Verify(dd => dd.Dispose(), Times.Once());
        }
Exemplo n.º 4
0
        public void Process__raises_message_before_processing_dive()
        {
            var accessed = 0;

            var dives = new[] { new Dive(15, 50, 23, ""), new Dive(24, 20, 33, "") };
            var dr = new Mock<IDiveRepository>();
            dr.Setup(inp => inp.LoadDives()).Returns(dives);
            var sf = new Mock<ISampleFactory>();
            Func<DlImageParsr.Model.Dive, IImageParser> facFunc = d => { return new Mock<IImageParser>().Object; };

            var machine = new Machine(dr.Object, sf.Object, facFunc);
            machine.ProcessMessage += (d) => accessed++;

            machine.Process();

            accessed.Should().BeGreaterOrEqualTo(2);
        }
Exemplo n.º 5
0
        public void Process__stores_processed_dives_but_not_nulls()
        {
            var accessed = 0;

            var parserMock = new Mock<IImageParser>();
            var pixels = new[] { new Pixel(2, 3), new Pixel(3, 4), new Pixel(5, 4) };
            parserMock.Setup(d => d.ReadDocument()).Returns(pixels);

            var dives = new[] { new Dive(14, 50, 23, ""), new Dive(14, 50, 23, "") };
            var dr = new Mock<IDiveRepository>();
            dr.Setup(inp => inp.LoadDives()).Returns(dives);

            var sf = new Mock<ISampleFactory>();
            var processed = new[] { new ProcessedDive(dives[0]), null };
            sf.Setup(inp => inp.Create(It.IsAny<IEnumerable<Pixel>>(), dives[0])).Returns(processed[0]);
            sf.Setup(inp => inp.Create(It.IsAny<IEnumerable<Pixel>>(), dives[1])).Returns(processed[1]);

            Func<DlImageParsr.Model.Dive, IImageParser> facFunc = d => { if (dives.Contains(d)) accessed++; return parserMock.Object; };

            var machine = new Machine(dr.Object, sf.Object, facFunc);

            machine.Process();

            dr.Verify(inp => inp.SaveDive(It.IsAny<ProcessedDive>() ), Times.Once());
        }
Exemplo n.º 6
0
        public void Process__put_pixels_into_SampleFactory()
        {
            var accessed = 0;

            var parserMock = new Mock<IImageParser>();
            var pixels = new [] { new Pixel(2,3), new Pixel(3,4), new Pixel(5,4) };
            parserMock.Setup(d => d.ReadDocument()).Returns(pixels);

            var dives = new[] { new Dive(14, 50, 23, ""), new Dive(24, 20, 33, "") };
            var dr = new Mock<IDiveRepository>();
            dr.Setup(inp => inp.LoadDives()).Returns(dives);

            var sf = new Mock<ISampleFactory>();

            Func<DlImageParsr.Model.Dive, IImageParser> facFunc = d => { if (dives.Contains(d)) accessed++; return parserMock.Object; };
            var machine = new Machine(dr.Object, sf.Object, facFunc);

            machine.Process();

            sf.Verify(inp => inp.Create(pixels, dives[0]), Times.Once());
            sf.Verify(inp => inp.Create(pixels, dives[1]), Times.Once());
        }
Exemplo n.º 7
0
        public void Process__gets_parses_the_images()
        {
            var accessed = 0;

            var parserMock = new Mock<IImageParser>();

            var dives = new[] { new Dive(14, 50, 23, ""), new Dive(24, 20, 33, "") };
            var dr = new Mock<IDiveRepository>();
            dr.Setup(inp => inp.LoadDives()).Returns(dives);
            var sf = new Mock<ISampleFactory>();
            Func<DlImageParsr.Model.Dive, IImageParser> facFunc = d => { if (dives.Contains(d)) accessed++; return parserMock.Object; };

            var machine = new Machine(dr.Object, sf.Object, facFunc);

            machine.Process();

            parserMock.Verify(d => d.ReadDocument(), Times.Exactly(2));
        }
Exemplo n.º 8
0
        public void Process__gets_Image_parser_from_factory_method_but_not_for_null_values()
        {
            var accessed = 0;

            var dives = new[] { new Dive(15, 50, 23, ""), new Dive(24, 20, 33, ""), null };
            var dr = new Mock<IDiveRepository>();
            dr.Setup(inp => inp.LoadDives()).Returns(dives);
            var sf = new Mock<ISampleFactory>();
            Func<DlImageParsr.Model.Dive, IImageParser> facFunc = d => { accessed += d.DiveLogId; return new Mock<IImageParser>().Object; };

            var machine = new Machine(dr.Object, sf.Object, facFunc);

            machine.Process();

            accessed.Should().Be(39);
        }
Exemplo n.º 9
0
        public void Process__gets_data_from_repository()
        {
            var dr = new Mock<IDiveRepository>();
            var sf = new Mock<ISampleFactory>();
            Func<DlImageParsr.Model.Dive, IImageParser> facFunc = d => new Mock<IImageParser>().Object;

            var machine = new Machine(dr.Object, sf.Object, facFunc);
            machine.Process();

            dr.Verify(o => o.LoadDives(), Times.Once());
        }
Exemplo n.º 10
0
        public void Process__dont_put_pixels_into_SampleFactory_but_not_for_null_values()
        {
            var accessed = 0;

            var parserMock = new Mock<IImageParser>();
            Pixel[] pixels = null;
            parserMock.Setup(d => d.ReadDocument()).Returns(pixels);

            var dives = new[] { new Dive(14, 50, 23, ""), new Dive(24, 20, 33, "") };
            var dr = new Mock<IDiveRepository>();
            dr.Setup(inp => inp.LoadDives()).Returns(dives);

            var sf = new Mock<ISampleFactory>();

            Func<DlImageParsr.Model.Dive, IImageParser> facFunc = d => { if (dives.Contains(d)) accessed++; return parserMock.Object; };
            var machine = new Machine(dr.Object, sf.Object, facFunc);

            machine.Process();

            sf.Verify(inp => inp.Create(pixels, It.IsAny<Dive>()), Times.Never());
            parserMock.Verify(inp => inp.Dispose(), Times.Exactly(2));
        }