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 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
        }
Beispiel #3
0
        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
        }
Beispiel #4
0
        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
        }
Beispiel #5
0
        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
        }
Beispiel #6
0
        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 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 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 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
        }
Beispiel #11
0
        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
        }
Beispiel #12
0
        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
        }
Beispiel #13
0
        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 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
        }
Beispiel #15
0
        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 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 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 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 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 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
 }