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 }
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 DeleteProductCommandCanExecuteWhenProductIsSelected() { // Fixture setup var fixture = new AutoMoqFixture(); var sut = fixture.CreateAnonymous <MainWindowViewModel>(); sut.Products.Add(fixture.Build <ProductViewModel>() .With(x => x.IsSelected, true) .CreateAnonymous()); // Exercise system var result = fixture.Get((object p) => sut.DeleteProductCommand.CanExecute(p)); // Verify outcome Assert.True(result, "DeleteProductCommand"); // 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 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 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 DeleteProductCommandCanExecuteWhenProductIsSelected() { // Fixture setup var fixture = new AutoMoqFixture(); var sut = fixture.CreateAnonymous<MainWindowViewModel>(); sut.Products.Add(fixture.Build<ProductViewModel>() .With(x => x.IsSelected, true) .CreateAnonymous()); // Exercise system var result = fixture.Get((object p) => sut.DeleteProductCommand.CanExecute(p)); // Verify outcome Assert.True(result, "DeleteProductCommand"); // 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 }