Ejemplo n.º 1
0
        public void ExecuteEditProductCommandWillNotUpdateOnAgentWhenReturnValueIsFalse()
        {
            // Fixture setup
            var fixture = new AutoMoqFixture();

            fixture.Freeze <Mock <IWindow> >().Setup(w => w.CreateChild(It.IsAny <object>())).Returns(() =>
            {
                var childStub = fixture.CreateAnonymous <Mock <IWindow> >();
                childStub.Setup(cw => cw.ShowDialog()).Returns(false);
                return(childStub.Object);
            });

            var agentMock = fixture.Freeze <Mock <IProductManagementAgent> >();

            var sut = fixture.CreateAnonymous <MainWindowViewModel>();

            sut.Products.Add(fixture.Build <ProductViewModel>()
                             .With(x => x.IsSelected, true)
                             .CreateAnonymous());
            // Exercise system
            fixture.Do((object p) => sut.EditProductCommand.Execute(p));
            // Verify outcome
            agentMock.Verify(a => a.InsertProduct(It.IsAny <ProductEditorViewModel>()), Times.Never());
            // Teardown
        }
Ejemplo n.º 2
0
        public void ExecuteEditProductCommandWillShowCorrectDialog()
        {
            // Fixture setup
            var fixture = new AutoMoqFixture();
            var product = fixture.Build <ProductViewModel>()
                          .With(x => x.IsSelected, true)
                          .CreateAnonymous();
            var expectedEditor = product.Edit().AsSource().OfLikeness <ProductEditorViewModel>()
                                 .With(d => d.Title).EqualsWhen((s, d) => "Edit Product" == d.Title);

            var childWindowMock = fixture.CreateAnonymous <Mock <IWindow> >();
            var windowStub      = fixture.Freeze <Mock <IWindow> >();

            windowStub.Setup(w => w.CreateChild(expectedEditor))
            .Returns(childWindowMock.Object);

            var sut = fixture.CreateAnonymous <MainWindowViewModel>();

            sut.Products.Add(product);
            // Exercise system
            fixture.Do((object p) => sut.EditProductCommand.Execute(p));
            // Verify outcome
            childWindowMock.Verify(w => w.ShowDialog());
            // Teardown
        }
Ejemplo n.º 3
0
        public void ExecuteInsertProductCommandWillReloadProducts()
        {
            // Fixture setup
            var fixture = new AutoMoqFixture();

            fixture.Freeze <Mock <IWindow> >().Setup(w => w.CreateChild(It.IsAny <object>())).Returns(() =>
            {
                var childStub = fixture.CreateAnonymous <Mock <IWindow> >();
                childStub.Setup(cw => cw.ShowDialog()).Returns(true);
                return(childStub.Object);
            });
            var agentMock = fixture.Freeze <Mock <IProductManagementAgent> >();

            var sut = fixture.CreateAnonymous <MainWindowViewModel>();

            // Exercise system
            fixture.Do((object p) => sut.InsertProductCommand.Execute(p));
            // Verify outcome
            agentMock.Verify(a => a.SelectAllProducts());
            // Teardown
        }
Ejemplo n.º 4
0
        public void ExecuteEditProductCommandWillUpdateOnAgentWhenReturnValueIsTrue()
        {
            // Fixture setup
            var fixture = new AutoMoqFixture();
            var product = fixture.Build <ProductViewModel>()
                          .With(x => x.IsSelected, true)
                          .CreateAnonymous();
            var editor = product.Edit().AsSource().OfLikeness <ProductEditorViewModel>()
                         .With(d => d.Title).EqualsWhen((s, d) => "Edit Product" == d.Title)
                         .Without(d => d.Error)
                         .Without(d => d.IsValid)
                         .Without(d => d.Title);

            fixture.Freeze <Mock <IWindow> >()
            .Setup(w => w.CreateChild(It.IsAny <object>()))
            .Callback((object vm) =>
            {
                var pVM      = (ProductEditorViewModel)vm;
                pVM.Currency = editor.Value.Currency;
                pVM.Name     = editor.Value.Name;
                pVM.Price    = editor.Value.Price;
            })
            .Returns(() =>
            {
                var childStub = fixture.CreateAnonymous <Mock <IWindow> >();
                childStub.Setup(cw => cw.ShowDialog()).Returns(true);
                return(childStub.Object);
            });

            var agentMock = fixture.Freeze <Mock <IProductManagementAgent> >();

            var sut = fixture.CreateAnonymous <MainWindowViewModel>();

            sut.Products.Add(product);
            // Exercise system
            fixture.Do((object p) => sut.EditProductCommand.Execute(p));
            // Verify outcome
            agentMock.Verify(a => a.UpdateProduct(It.Is <ProductEditorViewModel>(pvm => editor.Equals(pvm))));
            // Teardown
        }
Ejemplo n.º 5
0
        public void ExecuteInsertProductCommandWillNotInsertIntoAgentWhenReturnValueIsNull()
        {
            // Fixture setup
            var fixture = new AutoMoqFixture();

            fixture.Freeze <Mock <IWindow> >().Setup(w => w.CreateChild(It.IsAny <object>())).Returns(() =>
            {
                var childStub = fixture.CreateAnonymous <Mock <IWindow> >();
                childStub.Setup(cw => cw.ShowDialog()).Returns((bool?)null);
                return(childStub.Object);
            });

            var agentMock = fixture.Freeze <Mock <IProductManagementAgent> >();

            var sut = fixture.CreateAnonymous <MainWindowViewModel>();

            // Exercise system
            fixture.Do((object p) => sut.InsertProductCommand.Execute(p));
            // Verify outcome
            agentMock.Verify(a => a.InsertProduct(It.IsAny <ProductEditorViewModel>()), Times.Never());
            // Teardown
        }
Ejemplo n.º 6
0
        public void ExecuteRefreshCommandWillCorrectlyPopulateProducts()
        {
            // Fixture setup
            var fixture  = new AutoMoqFixture();
            var products = fixture.CreateMany <ProductViewModel>().ToList();

            fixture.Freeze <Mock <IProductManagementAgent> >().Setup(a => a.SelectAllProducts()).Returns(products);

            var sut = fixture.CreateAnonymous <MainWindowViewModel>();

            fixture.AddManyTo(sut.Products);
            // Exercise system
            fixture.Do((object p) => sut.RefreshCommand.Execute(p));
            // Verify outcome
            Assert.True(products.SequenceEqual(sut.Products), "RefreshCommand");
            // Teardown
        }
Ejemplo n.º 7
0
        public void ExecuteDeleteProductCommandWillReloadProducts()
        {
            // Fixture setup
            var fixture = new AutoMoqFixture();
            var product = fixture.Build <ProductViewModel>()
                          .With(x => x.IsSelected, true)
                          .CreateAnonymous();

            var agentMock = fixture.Freeze <Mock <IProductManagementAgent> >();

            var sut = fixture.CreateAnonymous <MainWindowViewModel>();

            sut.Products.Add(product);
            // Exercise system
            fixture.Do((object p) => sut.DeleteProductCommand.Execute(p));
            // Verify outcome
            agentMock.Verify(a => a.SelectAllProducts());
            // Teardown
        }
        public void ExecuteRefreshCommandWillCorrectlyPopulateProducts()
        {
            // Fixture setup
            var fixture = new AutoMoqFixture();
            var products = fixture.CreateMany<ProductViewModel>().ToList();

            fixture.Freeze<Mock<IProductManagementAgent>>().Setup(a => a.SelectAllProducts()).Returns(products);

            var sut = fixture.CreateAnonymous<MainWindowViewModel>();
            fixture.AddManyTo(sut.Products);
            // Exercise system
            fixture.Do((object p) => sut.RefreshCommand.Execute(p));
            // Verify outcome
            Assert.True(products.SequenceEqual(sut.Products), "RefreshCommand");
            // Teardown
        }
        public void ExecuteDeleteProductCommandWillReloadProducts()
        {
            // Fixture setup
            var fixture = new AutoMoqFixture();
            var product = fixture.Build<ProductViewModel>()
                .With(x => x.IsSelected, true)
                .CreateAnonymous();

            var agentMock = fixture.Freeze<Mock<IProductManagementAgent>>();

            var sut = fixture.CreateAnonymous<MainWindowViewModel>();
            sut.Products.Add(product);
            // Exercise system
            fixture.Do((object p) => sut.DeleteProductCommand.Execute(p));
            // Verify outcome
            agentMock.Verify(a => a.SelectAllProducts());
            // Teardown
        }
        public void ExecuteEditProductCommandWillReloadProducts()
        {
            // Fixture setup
            var fixture = new AutoMoqFixture();

            fixture.Freeze<Mock<IWindow>>().Setup(w => w.CreateChild(It.IsAny<object>())).Returns(() =>
                {
                    var childStub = fixture.CreateAnonymous<Mock<IWindow>>();
                    childStub.Setup(cw => cw.ShowDialog()).Returns(true);
                    return childStub.Object;
                });
            var agentMock = fixture.Freeze<Mock<IProductManagementAgent>>();

            var sut = fixture.CreateAnonymous<MainWindowViewModel>();
            sut.Products.Add(fixture.Build<ProductViewModel>()
                .With(x => x.IsSelected, true)
                .CreateAnonymous());
            // Exercise system
            fixture.Do((object p) => sut.EditProductCommand.Execute(p));
            // Verify outcome
            agentMock.Verify(a => a.SelectAllProducts());
            // Teardown
        }
        public void ExecuteEditProductCommandWillUpdateOnAgentWhenReturnValueIsTrue()
        {
            // Fixture setup
            var fixture = new AutoMoqFixture();
            var product = fixture.Build<ProductViewModel>()
                .With(x => x.IsSelected, true)
                .CreateAnonymous();
            var editor = product.Edit().AsSource().OfLikeness<ProductEditorViewModel>()
                .With(d => d.Title).EqualsWhen((s, d) => "Edit Product" == d.Title)
                .Without(d => d.Error)
                .Without(d => d.IsValid)
                .Without(d => d.Title);

            fixture.Freeze<Mock<IWindow>>()
                .Setup(w => w.CreateChild(It.IsAny<object>()))
                .Callback((object vm) =>
                    {
                        var pVM = (ProductEditorViewModel)vm;
                        pVM.Currency = editor.Value.Currency;
                        pVM.Name = editor.Value.Name;
                        pVM.Price = editor.Value.Price;
                    })
                .Returns(() =>
                    {
                        var childStub = fixture.CreateAnonymous<Mock<IWindow>>();
                        childStub.Setup(cw => cw.ShowDialog()).Returns(true);
                        return childStub.Object;
                    });

            var agentMock = fixture.Freeze<Mock<IProductManagementAgent>>();

            var sut = fixture.CreateAnonymous<MainWindowViewModel>();
            sut.Products.Add(product);
            // Exercise system
            fixture.Do((object p) => sut.EditProductCommand.Execute(p));
            // Verify outcome
            agentMock.Verify(a => a.UpdateProduct(It.Is<ProductEditorViewModel>(pvm => editor.Equals(pvm))));
            // Teardown
        }
        public void ExecuteEditProductCommandWillShowCorrectDialog()
        {
            // Fixture setup
            var fixture = new AutoMoqFixture();
            var product = fixture.Build<ProductViewModel>()
                .With(x => x.IsSelected, true)
                .CreateAnonymous();
            var expectedEditor = product.Edit().AsSource().OfLikeness<ProductEditorViewModel>()
                .With(d => d.Title).EqualsWhen((s, d) => "Edit Product" == d.Title);

            var childWindowMock = fixture.CreateAnonymous<Mock<IWindow>>();
            var windowStub = fixture.Freeze<Mock<IWindow>>();
            windowStub.Setup(w => w.CreateChild(expectedEditor))
                .Returns(childWindowMock.Object);

            var sut = fixture.CreateAnonymous<MainWindowViewModel>();
            sut.Products.Add(product);
            // Exercise system
            fixture.Do((object p) => sut.EditProductCommand.Execute(p));
            // Verify outcome
            childWindowMock.Verify(w => w.ShowDialog());
            // Teardown
        }
        public void ExecuteInsertProductCommandWillNotInsertIntoAgentWhenReturnValueIsFalse()
        {
            // Fixture setup
            var fixture = new AutoMoqFixture();

            fixture.Freeze<Mock<IWindow>>().Setup(w => w.CreateChild(It.IsAny<object>())).Returns(() =>
            {
                var childStub = fixture.CreateAnonymous<Mock<IWindow>>();
                childStub.Setup(cw => cw.ShowDialog()).Returns(false);
                return childStub.Object;
            });

            var agentMock = fixture.Freeze<Mock<IProductManagementAgent>>();

            var sut = fixture.CreateAnonymous<MainWindowViewModel>();
            // Exercise system
            fixture.Do((object p) => sut.InsertProductCommand.Execute(p));
            // Verify outcome
            agentMock.Verify(a => a.InsertProduct(It.IsAny<ProductEditorViewModel>()), Times.Never());
            // Teardown
        }