public void SucceedDoesNotThrowWhenStateIsClosed() { // Fixture setup var fixture = new WcfFixture(); var sut = fixture.CreateAnonymous<CircuitBreaker>(); // Exercise system sut.Succeed(); // Verify outcome (no exception indicates success); // Teardown }
public void SutIsCircuitBreaker() { // Fixture setup var fixture = new WcfFixture(); // Exercise system var sut = fixture.CreateAnonymous<CircuitBreaker>(); // Verify outcome Assert.IsAssignableFrom<ICircuitBreaker>(sut); // Teardown }
public void SutIsProductManagementAgent() { // Fixture setup var fixture = new WcfFixture(); // Exercise system var sut = fixture.CreateAnonymous<WcfProductManagementAgent>(); // Verify outcome Assert.IsAssignableFrom<IProductManagementAgent>(sut); // Teardown }
public void InsertNullProductWillThrow() { // Fixture setup var fixture = new WcfFixture(); var sut = fixture.CreateAnonymous<WcfProductManagementAgent>(); // Exercise system and verify outcome Assert.Throws<ArgumentNullException>(() => sut.InsertProduct(null)); // Teardown }
public void MapNullProductContractWillThrow() { // Fixture setup var fixture = new WcfFixture(); var sut = fixture.CreateAnonymous<ClientContractMapper>(); // Exercise system and verify outcome Assert.Throws<ArgumentNullException>(() => sut.Map((ProductContract)null)); // Teardown }
public void CreateWithNullFactoryWillThrow() { // Fixture setup var fixture = new WcfFixture(); var dummyMapper = fixture.CreateAnonymous<IClientContractMapper>(); // Exercise system and verify outcome Assert.Throws<ArgumentNullException>(() => new WcfProductManagementAgent(null, dummyMapper)); // Teardown }
public void CreateWithNullMapperWillThrow() { // Fixture setup var fixture = new WcfFixture(); var dummyFactory = fixture.CreateAnonymous<IProductChannelFactory>(); // Exercise system and verify outcome Assert.Throws<ArgumentNullException>(() => new WcfProductManagementAgent(dummyFactory, null)); // Teardown }
public void SutIsCircuitBreaker() { // Fixture setup var fixture = new WcfFixture(); // Exercise system var sut = fixture.CreateAnonymous <CircuitBreaker>(); // Verify outcome Assert.IsAssignableFrom <ICircuitBreaker>(sut); // Teardown }
public void DefaultStateIsClosed() { // Fixture setup var fixture = new WcfFixture(); var sut = fixture.CreateAnonymous<CircuitBreaker>(); // Exercise system ICircuitState result = sut.State; // Verify outcome Assert.IsAssignableFrom<ClosedCircuitState>(result); // Teardown }
public void InsertNullProductWillThrow() { // Fixture setup var fixture = new WcfFixture(); var sut = fixture.CreateAnonymous <WcfProductManagementAgent>(); // Exercise system and verify outcome Assert.Throws <ArgumentNullException>(() => sut.InsertProduct(null)); // Teardown }
public void CreateWithNullMapperWillThrow() { // Fixture setup var fixture = new WcfFixture(); var dummyFactory = fixture.CreateAnonymous <IProductChannelFactory>(); // Exercise system and verify outcome Assert.Throws <ArgumentNullException>(() => new WcfProductManagementAgent(dummyFactory, null)); // Teardown }
public void CreateWithNullFactoryWillThrow() { // Fixture setup var fixture = new WcfFixture(); var dummyMapper = fixture.CreateAnonymous <IClientContractMapper>(); // Exercise system and verify outcome Assert.Throws <ArgumentNullException>(() => new WcfProductManagementAgent(null, dummyMapper)); // Teardown }
public void SutIsProductManagementAgent() { // Fixture setup var fixture = new WcfFixture(); // Exercise system var sut = fixture.CreateAnonymous <WcfProductManagementAgent>(); // Verify outcome Assert.IsAssignableFrom <IProductManagementAgent>(sut); // Teardown }
public void TripWillTransitionToOpen() { // Fixture setup var fixture = new WcfFixture(); var sut = fixture.CreateAnonymous<CircuitBreaker>(); // Exercise system fixture.Do((Exception e) => sut.Trip(e)); // Verify outcome Assert.IsAssignableFrom<OpenCircuitState>(sut.State); // Teardown }
public void SucceedDoesNotThrowWhenStateIsClosed() { // Fixture setup var fixture = new WcfFixture(); var sut = fixture.CreateAnonymous <CircuitBreaker>(); // Exercise system sut.Succeed(); // Verify outcome (no exception indicates success); // Teardown }
public void MapNullProductContractsWillThrow() { // Fixture setup var fixture = new WcfFixture(); var sut = fixture.CreateAnonymous <ClientContractMapper>(); // Exercise system and verify outcome Assert.Throws <ArgumentNullException>(() => sut.Map((IEnumerable <ProductContract>)null).ToList()); // Teardown }
public void MapNullMoneyContractWillThrow() { // Fixture setup var fixture = new WcfFixture(); var sut = fixture.CreateAnonymous <ClientContractMapper>(); // Exercise system and verify outcome Assert.Throws <ArgumentNullException>(() => sut.Map((MoneyContract)null)); // Teardown }
public void DefaultStateIsClosed() { // Fixture setup var fixture = new WcfFixture(); var sut = fixture.CreateAnonymous <CircuitBreaker>(); // Exercise system ICircuitState result = sut.State; // Verify outcome Assert.IsAssignableFrom <ClosedCircuitState>(result); // Teardown }
public void TripWillTransitionToOpen() { // Fixture setup var fixture = new WcfFixture(); var sut = fixture.CreateAnonymous <CircuitBreaker>(); // Exercise system fixture.Do((Exception e) => sut.Trip(e)); // Verify outcome Assert.IsAssignableFrom <OpenCircuitState>(sut.State); // Teardown }
public void GuardWillThrowWhenStateIsOpen() { // Fixture setup var fixture = new WcfFixture(); fixture.Inject<TimeSpan>(1.Minutes()); var sut = fixture.CreateAnonymous<CircuitBreaker>(); sut.PutInOpenState(); // Exercise system and verify outcome Assert.Throws<InvalidOperationException>(() => sut.Guard()); // Teardown }
public void DeleteProductWillDeleteProductFromAgent() { // Fixture setup var fixture = new WcfFixture(); var id = fixture.CreateAnonymous<int>(); var agentMock = fixture.Freeze<Mock<IProductManagementAgent>>(); var sut = fixture.CreateAnonymous<CircuitBreakerProductManagementAgent>(); // Exercise system sut.DeleteProduct(id); // Verify outcome agentMock.Verify(a => a.DeleteProduct(id)); // Teardown }
public void GuardWillNotThrowWhenStateIsHalfOpen() { // Fixture setup var fixture = new WcfFixture(); fixture.Inject(1.Minutes()); var sut = fixture.CreateAnonymous <CircuitBreaker>(); sut.PutInHalfOpenState(); // Exercise system sut.Guard(); // Verify outcome (no exception indicates success) // Teardown }
public void GuardWillThrowWhenStateIsOpen() { // Fixture setup var fixture = new WcfFixture(); fixture.Inject <TimeSpan>(1.Minutes()); var sut = fixture.CreateAnonymous <CircuitBreaker>(); sut.PutInOpenState(); // Exercise system and verify outcome Assert.Throws <InvalidOperationException>(() => sut.Guard()); // Teardown }
public void DeleteProductWillDeleteProductFromAgent() { // Fixture setup var fixture = new WcfFixture(); var id = fixture.CreateAnonymous <int>(); var agentMock = fixture.Freeze <Mock <IProductManagementAgent> >(); var sut = fixture.CreateAnonymous <CircuitBreakerProductManagementAgent>(); // Exercise system sut.DeleteProduct(id); // Verify outcome agentMock.Verify(a => a.DeleteProduct(id)); // Teardown }
public void MapMoneyContractWillReturnCorrectResult() { // Fixture setup var fixture = new WcfFixture(); var contract = fixture.CreateAnonymous<MoneyContract>(); var expectedVM = contract.AsSource().OfLikeness<MoneyViewModel>(); var sut = fixture.CreateAnonymous<ClientContractMapper>(); // Exercise system var result = sut.Map(contract); // Verify outcome Assert.True(expectedVM.Equals(result)); // Teardown }
public void UpdateProductWillInsertProductInAgent() { // Fixture setup var fixture = new WcfFixture(); var product = fixture.CreateAnonymous <ProductEditorViewModel>(); var agentMock = fixture.Freeze <Mock <IProductManagementAgent> >(); var sut = fixture.CreateAnonymous <CircuitBreakerProductManagementAgent>(); // Exercise system sut.UpdateProduct(product); // Verify outcome agentMock.Verify(a => a.UpdateProduct(product)); // Teardown }
public void MapMoneyContractWillReturnCorrectResult() { // Fixture setup var fixture = new WcfFixture(); var contract = fixture.CreateAnonymous <MoneyContract>(); var expectedVM = contract.AsSource().OfLikeness <MoneyViewModel>(); var sut = fixture.CreateAnonymous <ClientContractMapper>(); // Exercise system var result = sut.Map(contract); // Verify outcome Assert.True(expectedVM.Equals(result)); // Teardown }
public void SucceedWilTransitionToClosedWhenStateIsHalfOpen() { // Fixture setup var fixture = new WcfFixture(); fixture.Inject(1.Minutes()); var sut = fixture.CreateAnonymous <CircuitBreaker>(); sut.PutInHalfOpenState(); // Exercise system sut.Succeed(); // Verify outcome Assert.IsAssignableFrom <ClosedCircuitState>(sut.State); // Teardown }
public void SelectAllProductsWillReturnCorrectResult() { // Fixture setup var fixture = new WcfFixture(); var expectedProducts = fixture.CreateMany <ProductViewModel>().ToList(); fixture.Freeze <Mock <IProductManagementAgent> >().Setup(a => a.SelectAllProducts()).Returns(expectedProducts); var sut = fixture.CreateAnonymous <CircuitBreakerProductManagementAgent>(); // Exercise system var result = sut.SelectAllProducts(); // Verify outcome Assert.Equal(expectedProducts, result); // Teardown }
public void MapProductContractWillReturnCorrectResult() { // Fixture setup var fixture = new WcfFixture(); var contract = fixture.CreateAnonymous<ProductContract>(); var expectedVM = contract.AsSource().OfLikeness<ProductViewModel>() .With(d => d.UnitPrice).EqualsWhen((s, d) => s.UnitPrice.AsSource().OfLikeness<MoneyViewModel>().Equals(d.UnitPrice)) .Without(d => d.IsSelected); var sut = fixture.CreateAnonymous<ClientContractMapper>(); // Exercise system var result = sut.Map(contract); // Verify outcome Assert.True(expectedVM.Equals(result)); // Teardown }
public void DeleteProductWillRethrow() { // Fixture setup var fixture = new WcfFixture(); var expectedException = fixture.CreateAnonymous<InvalidOperationException>(); fixture.Freeze<Mock<IProductManagementAgent>>().Setup(a => a.DeleteProduct(It.IsAny<int>())).Throws(expectedException); var verified = false; var sut = fixture.CreateAnonymous<CircuitBreakerProductManagementAgent>(); // Exercise system try { fixture.Do((int id) => sut.DeleteProduct(id)); } // Verify outcome catch (InvalidOperationException e) { verified = e == expectedException; } finally { Assert.True(verified); } // Teardown }
public void MapProductContractWillReturnCorrectResult() { // Fixture setup var fixture = new WcfFixture(); var contract = fixture.CreateAnonymous <ProductContract>(); var expectedVM = contract.AsSource().OfLikeness <ProductViewModel>() .With(d => d.UnitPrice).EqualsWhen((s, d) => s.UnitPrice.AsSource().OfLikeness <MoneyViewModel>().Equals(d.UnitPrice)) .Without(d => d.IsSelected); var sut = fixture.CreateAnonymous <ClientContractMapper>(); // Exercise system var result = sut.Map(contract); // Verify outcome Assert.True(expectedVM.Equals(result)); // Teardown }
public void DeleteProductWillTripBreakerWhenAgentThrows() { // Fixture setup var fixture = new WcfFixture(); var e = fixture.CreateAnonymous<TimeoutException>(); var breakerMock = fixture.Freeze<Mock<ICircuitBreaker>>(); fixture.Freeze<Mock<IProductManagementAgent>>().Setup(a => a.DeleteProduct(It.IsAny<int>())).Throws(e); var sut = fixture.CreateAnonymous<CircuitBreakerProductManagementAgent>(); // Exercise system try { fixture.Do((int id) => sut.DeleteProduct(id)); } // Verify outcome catch (TimeoutException) { } finally { breakerMock.Verify(b => b.Trip(e)); } // Teardown }
public void DeleteProductWillRethrow() { // Fixture setup var fixture = new WcfFixture(); var expectedException = fixture.CreateAnonymous <InvalidOperationException>(); fixture.Freeze <Mock <IProductManagementAgent> >().Setup(a => a.DeleteProduct(It.IsAny <int>())).Throws(expectedException); var verified = false; var sut = fixture.CreateAnonymous <CircuitBreakerProductManagementAgent>(); // Exercise system try { fixture.Do((int id) => sut.DeleteProduct(id)); } // Verify outcome catch (InvalidOperationException e) { verified = e == expectedException; } finally { Assert.True(verified); } // Teardown }
public void DeleteProductWillDeleteFromChannel() { // Fixture setup var fixture = new WcfFixture(); var id = fixture.CreateAnonymous <int>(); var channelMock = fixture.CreateAnonymous <Mock <IProductManagementServiceChannel> >(); fixture.Freeze <Mock <IProductChannelFactory> >().Setup(f => f.CreateChannel()).Returns(channelMock.Object); var sut = fixture.CreateAnonymous <WcfProductManagementAgent>(); // Exercise system sut.DeleteProduct(id); // Verify outcome channelMock.Verify(c => c.DeleteProduct(id)); // Teardown }
public void DeleteProductWillOrchestrateBreakerCorrectly() { // Fixture setup var fixture = new WcfFixture(); var spy = new List<int>(); var breakerStub = fixture.Freeze<Mock<ICircuitBreaker>>(); breakerStub.Setup(cb => cb.Guard()).Callback(() => spy.Add(1)); fixture.Freeze<Mock<IProductManagementAgent>>().Setup(a => a.DeleteProduct(It.IsAny<int>())).Callback(() => spy.Add(2)); breakerStub.Setup(b => b.Succeed()).Callback(() => spy.Add(3)); var sut = fixture.CreateAnonymous<CircuitBreakerProductManagementAgent>(); // Exercise system fixture.Do((int id) => sut.DeleteProduct(id)); // Verify outcome Assert.True(Enumerable.Range(1, 3).SequenceEqual(spy)); // Teardown }
public void MapProductContractsWillReturnCorrectResult() { // Fixture setup var fixture = new WcfFixture(); var contracts = fixture.CreateMany <ProductContract>().ToList(); var expectedVMs = (from c in contracts select c.AsSource().OfLikeness <ProductViewModel>() .With(d => d.UnitPrice).EqualsWhen((s, d) => s.UnitPrice.AsSource().OfLikeness <MoneyViewModel>().Equals(d.UnitPrice)) .Without(d => d.IsSelected)).ToList(); var sut = fixture.CreateAnonymous <ClientContractMapper>(); // Exercise system var result = sut.Map(contracts); // Verify outcome Assert.True(expectedVMs.Cast <object>().SequenceEqual(result.Cast <object>())); // Teardown }
public void GuardWillTransitionToHalfOpenWhenStateIsOpenAndTimeoutIsReached() { // Fixture setup var fixture = new WcfFixture(); DateTime.Now.Freeze(); fixture.Inject(1.Minutes()); var sut = fixture.CreateAnonymous <CircuitBreaker>(); sut.PutInOpenState(); 2.Minutes().Pass(); // Exercise system sut.Guard(); // Verify outcome Assert.IsAssignableFrom <HalfOpenCircuitState>(sut.State); // Teardown }
public void SelectAllProductsWillTripBreakerWhenAgentThrows() { // Fixture setup var fixture = new WcfFixture(); var e = fixture.CreateAnonymous <TimeoutException>(); var breakerMock = fixture.Freeze <Mock <ICircuitBreaker> >(); fixture.Freeze <Mock <IProductManagementAgent> >().Setup(a => a.SelectAllProducts()).Throws(e); var sut = fixture.CreateAnonymous <CircuitBreakerProductManagementAgent>(); // Exercise system try { sut.SelectAllProducts().ToList(); } // Verify outcome catch (TimeoutException) { } finally { breakerMock.Verify(b => b.Trip(e)); } // Teardown }
public void DeleteProductWillTripBreakerWhenAgentThrows() { // Fixture setup var fixture = new WcfFixture(); var e = fixture.CreateAnonymous <TimeoutException>(); var breakerMock = fixture.Freeze <Mock <ICircuitBreaker> >(); fixture.Freeze <Mock <IProductManagementAgent> >().Setup(a => a.DeleteProduct(It.IsAny <int>())).Throws(e); var sut = fixture.CreateAnonymous <CircuitBreakerProductManagementAgent>(); // Exercise system try { fixture.Do((int id) => sut.DeleteProduct(id)); } // Verify outcome catch (TimeoutException) { } finally { breakerMock.Verify(b => b.Trip(e)); } // Teardown }
public void MapProductEditorViewModelWillReturnCorrectResult() { // Fixture setup var fixture = new WcfFixture(); var vm = fixture.Build <ProductEditorViewModel>() .With(x => x.Price, fixture.CreateAnonymous <decimal>().ToString()) .CreateAnonymous(); var expectedContract = vm.AsSource().OfLikeness <ProductContract>() .With(d => d.UnitPrice).EqualsWhen((s, d) => s.Currency == d.UnitPrice.CurrencyCode && decimal.Parse(s.Price) == d.UnitPrice.Amount) .Without(d => d.ExtensionData); var sut = fixture.CreateAnonymous <ClientContractMapper>(); // Exercise system var result = sut.Map(vm); // Verify outcome Assert.True(expectedContract.Equals(result)); // Teardown }
public void InsertProductWillInsertCorrectlyInChannel() { // Fixture setup var fixture = new WcfFixture(); var vm = fixture.CreateAnonymous <ProductEditorViewModel>(); var contract = fixture.CreateAnonymous <ProductContract>(); var channelMock = fixture.CreateAnonymous <Mock <IProductManagementServiceChannel> >(); fixture.Freeze <Mock <IProductChannelFactory> >().Setup(f => f.CreateChannel()).Returns(channelMock.Object); fixture.Freeze <Mock <IClientContractMapper> >().Setup(m => m.Map(vm)).Returns(contract); var sut = fixture.CreateAnonymous <WcfProductManagementAgent>(); // Exercise system sut.InsertProduct(vm); // Verify outcome channelMock.Verify(c => c.InsertProduct(contract)); // Teardown }
public void SelectAllProductsWillOrchestrateBreakerCorrectly() { // Fixture setup var fixture = new WcfFixture(); var spy = new List <int>(); var breakerStub = fixture.Freeze <Mock <ICircuitBreaker> >(); breakerStub.Setup(cb => cb.Guard()).Callback(() => spy.Add(1)); fixture.Freeze <Mock <IProductManagementAgent> >().Setup(a => a.SelectAllProducts()).Callback(() => spy.Add(2)).Returns(fixture.CreateMany <ProductViewModel>()); breakerStub.Setup(b => b.Succeed()).Callback(() => spy.Add(3)); var sut = fixture.CreateAnonymous <CircuitBreakerProductManagementAgent>(); // Exercise system sut.SelectAllProducts().ToList(); // Verify outcome Assert.True(Enumerable.Range(1, 3).SequenceEqual(spy)); // Teardown }
public void DeleteProductWillOrchestrateBreakerCorrectly() { // Fixture setup var fixture = new WcfFixture(); var spy = new List <int>(); var breakerStub = fixture.Freeze <Mock <ICircuitBreaker> >(); breakerStub.Setup(cb => cb.Guard()).Callback(() => spy.Add(1)); fixture.Freeze <Mock <IProductManagementAgent> >().Setup(a => a.DeleteProduct(It.IsAny <int>())).Callback(() => spy.Add(2)); breakerStub.Setup(b => b.Succeed()).Callback(() => spy.Add(3)); var sut = fixture.CreateAnonymous <CircuitBreakerProductManagementAgent>(); // Exercise system fixture.Do((int id) => sut.DeleteProduct(id)); // Verify outcome Assert.True(Enumerable.Range(1, 3).SequenceEqual(spy)); // Teardown }
public void SelectAllProductsWillReturnCorrectResult() { // Fixture setup var fixture = new WcfFixture(); var contracts = fixture.CreateMany<ProductContract>().ToArray(); var productsVMs = fixture.CreateMany<ProductViewModel>().ToList(); fixture.Freeze<Mock<IProductChannelFactory>>().Setup(f => f.CreateChannel()).Returns(() => { var chStub = fixture.CreateAnonymous<Mock<IProductManagementServiceChannel>>(); chStub.Setup(c => c.SelectAllProducts()).Returns(contracts); return chStub.Object; }); fixture.Freeze<Mock<IClientContractMapper>>().Setup(m => m.Map(contracts)).Returns(productsVMs); var sut = fixture.CreateAnonymous<WcfProductManagementAgent>(); // Exercise system var result = sut.SelectAllProducts(); // Verify outcome Assert.True(productsVMs.SequenceEqual(result)); // Teardown }
public void SelectAllProductsWillReturnCorrectResult() { // Fixture setup var fixture = new WcfFixture(); var contracts = fixture.CreateMany <ProductContract>().ToArray(); var productsVMs = fixture.CreateMany <ProductViewModel>().ToList(); fixture.Freeze <Mock <IProductChannelFactory> >().Setup(f => f.CreateChannel()).Returns(() => { var chStub = fixture.CreateAnonymous <Mock <IProductManagementServiceChannel> >(); chStub.Setup(c => c.SelectAllProducts()).Returns(contracts); return(chStub.Object); }); fixture.Freeze <Mock <IClientContractMapper> >().Setup(m => m.Map(contracts)).Returns(productsVMs); var sut = fixture.CreateAnonymous <WcfProductManagementAgent>(); // Exercise system var result = sut.SelectAllProducts(); // Verify outcome Assert.True(productsVMs.SequenceEqual(result)); // Teardown }
public void SucceedWilTransitionToClosedWhenStateIsHalfOpen() { // Fixture setup var fixture = new WcfFixture(); fixture.Inject(1.Minutes()); var sut = fixture.CreateAnonymous<CircuitBreaker>(); sut.PutInHalfOpenState(); // Exercise system sut.Succeed(); // Verify outcome Assert.IsAssignableFrom<ClosedCircuitState>(sut.State); // Teardown }
public void GuardWillNotThrowWhenStateIsHalfOpen() { // Fixture setup var fixture = new WcfFixture(); fixture.Inject(1.Minutes()); var sut = fixture.CreateAnonymous<CircuitBreaker>(); sut.PutInHalfOpenState(); // Exercise system sut.Guard(); // Verify outcome (no exception indicates success) // Teardown }
public void SelectAllProductsWillReturnCorrectResult() { // Fixture setup var fixture = new WcfFixture(); var expectedProducts = fixture.CreateMany<ProductViewModel>().ToList(); fixture.Freeze<Mock<IProductManagementAgent>>().Setup(a => a.SelectAllProducts()).Returns(expectedProducts); var sut = fixture.CreateAnonymous<CircuitBreakerProductManagementAgent>(); // Exercise system var result = sut.SelectAllProducts(); // Verify outcome Assert.Equal(expectedProducts, result); // Teardown }
public void SelectAllProductsWillOrchestrateBreakerCorrectly() { // Fixture setup var fixture = new WcfFixture(); var spy = new List<int>(); var breakerStub = fixture.Freeze<Mock<ICircuitBreaker>>(); breakerStub.Setup(cb => cb.Guard()).Callback(() => spy.Add(1)); fixture.Freeze<Mock<IProductManagementAgent>>().Setup(a => a.SelectAllProducts()).Callback(() => spy.Add(2)).Returns(fixture.CreateMany<ProductViewModel>()); breakerStub.Setup(b => b.Succeed()).Callback(() => spy.Add(3)); var sut = fixture.CreateAnonymous<CircuitBreakerProductManagementAgent>(); // Exercise system sut.SelectAllProducts().ToList(); // Verify outcome Assert.True(Enumerable.Range(1, 3).SequenceEqual(spy)); // Teardown }
public void SelectAllProductsWillTripBreakerWhenAgentThrows() { // Fixture setup var fixture = new WcfFixture(); var e = fixture.CreateAnonymous<TimeoutException>(); var breakerMock = fixture.Freeze<Mock<ICircuitBreaker>>(); fixture.Freeze<Mock<IProductManagementAgent>>().Setup(a => a.SelectAllProducts()).Throws(e); var sut = fixture.CreateAnonymous<CircuitBreakerProductManagementAgent>(); // Exercise system try { sut.SelectAllProducts().ToList(); } // Verify outcome catch (TimeoutException) { } finally { breakerMock.Verify(b => b.Trip(e)); } // Teardown }
public void InsertProductWillInsertCorrectlyInChannel() { // Fixture setup var fixture = new WcfFixture(); var vm = fixture.CreateAnonymous<ProductEditorViewModel>(); var contract = fixture.CreateAnonymous<ProductContract>(); var channelMock = fixture.CreateAnonymous<Mock<IProductManagementServiceChannel>>(); fixture.Freeze<Mock<IProductChannelFactory>>().Setup(f => f.CreateChannel()).Returns(channelMock.Object); fixture.Freeze<Mock<IClientContractMapper>>().Setup(m => m.Map(vm)).Returns(contract); var sut = fixture.CreateAnonymous<WcfProductManagementAgent>(); // Exercise system sut.InsertProduct(vm); // Verify outcome channelMock.Verify(c => c.InsertProduct(contract)); // Teardown }
public void MapProductContractsWillReturnCorrectResult() { // Fixture setup var fixture = new WcfFixture(); var contracts = fixture.CreateMany<ProductContract>().ToList(); var expectedVMs = (from c in contracts select c.AsSource().OfLikeness<ProductViewModel>() .With(d => d.UnitPrice).EqualsWhen((s, d) => s.UnitPrice.AsSource().OfLikeness<MoneyViewModel>().Equals(d.UnitPrice)) .Without(d => d.IsSelected)).ToList(); var sut = fixture.CreateAnonymous<ClientContractMapper>(); // Exercise system var result = sut.Map(contracts); // Verify outcome Assert.True(expectedVMs.Cast<object>().SequenceEqual(result.Cast<object>())); // Teardown }
public void InsertProductWillInsertProductInAgent() { // Fixture setup var fixture = new WcfFixture(); var product = fixture.CreateAnonymous<ProductEditorViewModel>(); var agentMock = fixture.Freeze<Mock<IProductManagementAgent>>(); var sut = fixture.CreateAnonymous<CircuitBreakerProductManagementAgent>(); // Exercise system sut.InsertProduct(product); // Verify outcome agentMock.Verify(a => a.InsertProduct(product)); // Teardown }
public void DeleteProductWillDeleteFromChannel() { // Fixture setup var fixture = new WcfFixture(); var id = fixture.CreateAnonymous<int>(); var channelMock = fixture.CreateAnonymous<Mock<IProductManagementServiceChannel>>(); fixture.Freeze<Mock<IProductChannelFactory>>().Setup(f => f.CreateChannel()).Returns(channelMock.Object); var sut = fixture.CreateAnonymous<WcfProductManagementAgent>(); // Exercise system sut.DeleteProduct(id); // Verify outcome channelMock.Verify(c => c.DeleteProduct(id)); // Teardown }
public void GuardWillTransitionToHalfOpenWhenStateIsOpenAndTimeoutIsReached() { // Fixture setup var fixture = new WcfFixture(); DateTime.Now.Freeze(); fixture.Inject(1.Minutes()); var sut = fixture.CreateAnonymous<CircuitBreaker>(); sut.PutInOpenState(); 2.Minutes().Pass(); // Exercise system sut.Guard(); // Verify outcome Assert.IsAssignableFrom<HalfOpenCircuitState>(sut.State); // Teardown }
public void MapProductEditorViewModelWillReturnCorrectResult() { // Fixture setup var fixture = new WcfFixture(); var vm = fixture.Build<ProductEditorViewModel>() .With(x => x.Price, fixture.CreateAnonymous<decimal>().ToString()) .CreateAnonymous(); var expectedContract = vm.AsSource().OfLikeness<ProductContract>() .With(d => d.UnitPrice).EqualsWhen((s, d) => s.Currency == d.UnitPrice.CurrencyCode && decimal.Parse(s.Price) == d.UnitPrice.Amount) .Without(d => d.ExtensionData); var sut = fixture.CreateAnonymous<ClientContractMapper>(); // Exercise system var result = sut.Map(vm); // Verify outcome Assert.True(expectedContract.Equals(result)); // Teardown }