コード例 #1
0
 public void ChangingCurrencyWillRaiseNotifyEvent(ProductEditorViewModel sut, string currency)
 {
     // Fixture setup
     // Exercise system and verify outcome
     sut.ShouldNotifyOn(s => s.Currency).When(s => s.Currency = currency);
     // Teardown
 }
コード例 #2
0
        // Wraps call to decorated agent with Circuit Breaker error handling behavior
        // NOTE Functionality of Circuit Breaker
        public void InsertProduct(ProductEditorViewModel product)
        {
            // Checks the state of the Circuit Breaker
            // Let's user through when guard is either closed or Half open
            // Throws an exception when call is open
            // This ensures fast failure when call will not succeed
            // Ensures we never move past here when in the Open State
            this.breaker.Guard();
            try
            {
                // invoke decorated agent if we make it past the guard
                // breaker trips from call block if call fails
                this.innerAgent.InsertProduct(product);

                // If Call succeeds you signal the breaker to stay in the closed state
                // or transition back to Closed from Half-Open state
                // Impossible to signal success in OPen State.
                this.breaker.Succeed();
            }
            // This is a simple implementation in a real world scenario you
            // only want to catch exceptions on specific Exception types
            // You only want exceptions that indicate intermittent errors,
            // Exceptions like Null Reference rarely indicate this.
            catch (Exception e)
            {
                // From Closed and Half-Open States tripping the breaker
                // puts us in Open.
                // From Open State a time out determines when we move back
                // to Half-Open
                this.breaker.Trip(e);
                throw;
            }
        }
コード例 #3
0
 public void InsertProduct(ProductEditorViewModel product)
 {
     // This allows us to use the Circuit Breaker in a more succinct manner
     // A Method is passed to an Action or Func<T>
     this.breaker.Execute(() =>
                          this.innerAgent.InsertProduct(product));
 }
コード例 #4
0
 public void NotChangingTitleWillNotRaiseNotifyEvent(ProductEditorViewModel sut)
 {
     // Fixture setup
     // Exercise system and verify outcome
     sut.ShouldNotNotifyOn(s => s.Title).When(s => s.Title = s.Title);
     // Teardown
 }
コード例 #5
0
 public void ChangingPriceWillRaiseNotifyEvent(ProductEditorViewModel sut, string price)
 {
     // Fixture setup
     // Exercise system and verify outcome
     sut.ShouldNotifyOn(s => s.Price).When(s => s.Price = price);
     // Teardown
 }
コード例 #6
0
        //POST
        protected override DriverResult Editor(
            ProductPart part, IUpdateModel updater, dynamic shapeHelper)
        {
            var model = new ProductEditorViewModel {
                Product = part
            };

            if (updater.TryUpdateModel(model, Prefix, null, null))
            {
                if (model.PriceTiers != null)
                {
                    part.PriceTiers = model.PriceTiers.Select(t => new PriceTier()
                    {
                        Quantity     = t.Quantity,
                        Price        = (!t.Price.EndsWith("%") ? t.Price.ToDecimal() : null),
                        PricePercent =
                            (t.Price.EndsWith("%") ? t.Price.Substring(0, t.Price.Length - 1).ToDecimal() : null)
                    }).ToList();
                }
                else
                {
                    part.PriceTiers = new List <PriceTier>();
                }
                part.DiscountPrice = model.DiscountPrice == null
                    ? -1 : (decimal)model.DiscountPrice;
            }
            return(Editor(part, shapeHelper));
        }
コード例 #7
0
 public void ModificationThatDoesNotChangeValidStateWillNotRaiseNotifyEvent(ProductEditorViewModel sut, string price)
 {
     // Fixture setup
     // Exercise system and verify outcome
     sut.ShouldNotNotifyOn(s => s.IsValid).When(s => s.Price = price);
     // Teardown
 }
コード例 #8
0
 public void SettingNullCurrencyWillThrow(ProductEditorViewModel sut)
 {
     // Fixture setup
     // Exercise system and verify outcome
     Assert.Throws <ArgumentNullException>(() =>
                                           sut.Currency = null);
     // Teardown
 }
コード例 #9
0
 public void SutIsNotifyPropertyChanged(ProductEditorViewModel sut)
 {
     // Fixture setup
     // Exercise system
     // Verify outcome
     Assert.IsAssignableFrom <INotifyPropertyChanged>(sut);
     // Teardown
 }
コード例 #10
0
 public void SettingNullNameWillThrow(ProductEditorViewModel sut)
 {
     // Fixture setup
     // Exercise system and verify outcome
     Assert.Throws<ArgumentNullException>(() =>
         sut.Name = null);
     // Teardown
 }
コード例 #11
0
 public void SutIsDataErrorInfo(ProductEditorViewModel sut)
 {
     // Fixture setup
     // Exercise system
     // Verify outcome
     Assert.IsAssignableFrom <IDataErrorInfo>(sut);
     // Teardown
 }
コード例 #12
0
        public ProductEditorViewModel Edit()
        {
            var editor = new ProductEditorViewModel(this.Id);

            editor.Currency = this.UnitPrice.CurrencyCode;
            editor.Name     = this.Name;
            editor.Price    = this.UnitPrice.Amount.ToString("F");
            return(editor);
        }
コード例 #13
0
        public void IsValidIsFalseWhenSutIsInvalid(ProductEditorViewModel sut)
        {
            // Fixture setup
            // Exercise system
            var result = sut.IsValid;

            // Verify outcome
            Assert.False(result, "IsValid");
            // Teardown
        }
コード例 #14
0
        public void ErrorIsCorrectWhenSutIsInvalid(ProductEditorViewModel sut)
        {
            // Fixture setup
            // Exercise system
            var result = sut.Error;

            // Verify outcome
            Assert.Equal("One or more values are invalid.", result);
            // Teardown
        }
コード例 #15
0
 public void CurrencyIsProperWritableProperty(string expectedCurrency, ProductEditorViewModel sut)
 {
     // Fixture setup
     // Exercise system
     sut.Currency = expectedCurrency;
     string result = sut.Currency;
     // Verify outcome
     Assert.Equal(expectedCurrency, result);
     // Teardown
 }
コード例 #16
0
 public void NameIsProperWritableProperty(string expectedName, ProductEditorViewModel sut)
 {
     // Fixture setup
     // Exercise system
     sut.Name = expectedName;
     string result = sut.Name;
     // Verify outcome
     Assert.Equal(expectedName, result);
     // Teardown
 }
コード例 #17
0
        public void NameIsProperWritableProperty(string expectedName, ProductEditorViewModel sut)
        {
            // Fixture setup
            // Exercise system
            sut.Name = expectedName;
            string result = sut.Name;

            // Verify outcome
            Assert.Equal(expectedName, result);
            // Teardown
        }
コード例 #18
0
        public void CurrencyIsProperWritableProperty(string expectedCurrency, ProductEditorViewModel sut)
        {
            // Fixture setup
            // Exercise system
            sut.Currency = expectedCurrency;
            string result = sut.Currency;

            // Verify outcome
            Assert.Equal(expectedCurrency, result);
            // Teardown
        }
コード例 #19
0
        public void UpdateProduct(ProductEditorViewModel product)
        {
            if (product == null)
            {
                throw new ArgumentNullException("product");
            }

            using (var channel = this.factory.CreateChannel())
            {
                var pc = this.mapper.Map(product);
                channel.UpdateProduct(pc);
            }
        }
コード例 #20
0
 public void UpdateProduct(ProductEditorViewModel product)
 {
     this.breaker.Guard();
     try
     {
         this.innerAgent.UpdateProduct(product);
         this.breaker.Succeed();
     }
     catch (Exception e)
     {
         this.breaker.Trip(e);
         throw;
     }
 }
コード例 #21
0
 public void UpdateProduct(ProductEditorViewModel product)
 {
     try
     {
         this.innerAgent.UpdateProduct(product);
     }
     catch (CommunicationException e)
     {
         this.AlertUser(e.Message);
     }
     catch (InvalidOperationException e)
     {
         this.AlertUser(e.Message);
     }
 }
コード例 #22
0
        public void EditWillReturnCorrectResult(ProductViewModel sut)
        {
            // Fixture setup
            var expectedEditor = sut.AsSource().OfLikeness <ProductEditorViewModel>()
                                 .With(d => d.Currency).EqualsWhen((s, d) => s.UnitPrice.CurrencyCode == d.Currency)
                                 .With(d => d.Price).EqualsWhen((s, d) => s.UnitPrice.Amount.ToString("F") == d.Price)
                                 .Without(d => d.Error)
                                 .Without(d => d.IsValid)
                                 .Without(d => d.Title);
            // Exercise system
            ProductEditorViewModel result = sut.Edit();

            // Verify outcome
            Assert.True(expectedEditor.Equals(result));
            // Teardown
        }
コード例 #23
0
 public void InsertProduct(ProductEditorViewModel product)
 {
     try
     {
         // Decorated Agent
         this.innerAgent.InsertProduct(product);
     }
     catch (CommunicationException e)
     {
         // If fails Alert the User with Error Message
         this.AlertUser(e.Message);
     }
     catch (InvalidOperationException e)
     {
         this.AlertUser(e.Message);
     }
 }
コード例 #24
0
        public ProductContract Map(ProductEditorViewModel productEditorViewModel)
        {
            if (productEditorViewModel == null)
            {
                throw new ArgumentNullException("productEditorViewModel");
            }

            var pc = new ProductContract();

            pc.Id        = productEditorViewModel.Id;
            pc.Name      = productEditorViewModel.Name;
            pc.UnitPrice = new MoneyContract
            {
                Amount       = decimal.Parse(productEditorViewModel.Price),
                CurrencyCode = productEditorViewModel.Currency
            };
            return(pc);
        }
コード例 #25
0
        public void ExecuteInsertProductCommandWillShowCorrectDialog(Mock <IWindow> childWindowMock, [Frozen] Mock <IWindow> windowStub, MainWindowViewModel sut, object p)
        {
            // Fixture setup
            var expectedVM = new ProductEditorViewModel(0)
            {
                Currency = "DKK",
                Name     = string.Empty,
                Price    = string.Empty,
                Title    = "Add Product"
            }.AsSource().OfLikeness <ProductEditorViewModel>();

            windowStub.Setup(w => w.CreateChild(expectedVM))
            .Returns(childWindowMock.Object);
            // Exercise system
            sut.InsertProductCommand.Execute(p);
            // Verify outcome
            childWindowMock.Verify(w => w.ShowDialog());
            // Teardown
        }
コード例 #26
0
        protected override void OnInitialized()
        {
            try
            {
                //creating the view model will get the product data and grid parameters
                _gridViewModel = new ProductGridViewModel();

                _dialogViewModel = new DialogViewModel()
                {
                    ConfirmButtonName = "Ok", ShowCancelButton = false
                };

                _editorViewModel = new ProductEditorViewModel();
            }
            catch (System.Exception ex)
            {
                _dialogViewModel.Show("Error", ex.Message, ex);
            }
            base.OnInitialized();
        }
コード例 #27
0
 public void InsertProduct(ProductEditorViewModel product)
 {
     this.breaker.Execute(() =>
                          this.innerAgent.InsertProduct(product));
 }
コード例 #28
0
 public void SutIsDataErrorInfo(ProductEditorViewModel sut)
 {
     // Fixture setup
     // Exercise system
     // Verify outcome
     Assert.IsAssignableFrom<IDataErrorInfo>(sut);
     // Teardown
 }
コード例 #29
0
 public void ErrorIsCorrectWhenSutIsInvalid(ProductEditorViewModel sut)
 {
     // Fixture setup
     // Exercise system
     var result = sut.Error;
     // Verify outcome
     Assert.Equal("One or more values are invalid.", result);
     // Teardown
 }
コード例 #30
0
 public void ModificationThatDoesNotChangeValidStateWillNotRaiseNotifyEvent(ProductEditorViewModel sut, string price)
 {
     // Fixture setup
     // Exercise system and verify outcome
     sut.ShouldNotNotifyOn(s => s.IsValid).When(s => s.Price = price);
     // Teardown
 }
コード例 #31
0
 public void IsValidIsFalseWhenSutIsInvalid(ProductEditorViewModel sut)
 {
     // Fixture setup
     // Exercise system
     var result = sut.IsValid;
     // Verify outcome
     Assert.False(result, "IsValid");
     // Teardown
 }
コード例 #32
0
 public void SutIsNotifyPropertyChanged(ProductEditorViewModel sut)
 {
     // Fixture setup
     // Exercise system
     // Verify outcome
     Assert.IsAssignableFrom<INotifyPropertyChanged>(sut);
     // Teardown
 }
コード例 #33
0
        public void ExecuteInsertProductCommandWillShowCorrectDialog(Mock<IWindow> childWindowMock, [Frozen]Mock<IWindow> windowStub, MainWindowViewModel sut, object p)
        {
            // Fixture setup
            var expectedVM = new ProductEditorViewModel(0)
            {
                Currency = "DKK",
                Name = string.Empty,
                Price = string.Empty,
                Title = "Add Product"
            }.AsSource().OfLikeness<ProductEditorViewModel>();

            windowStub.Setup(w => w.CreateChild(expectedVM))
                .Returns(childWindowMock.Object);
            // Exercise system
            sut.InsertProductCommand.Execute(p);
            // Verify outcome
            childWindowMock.Verify(w => w.ShowDialog());
            // Teardown
        }
コード例 #34
0
 public void ChangingCurrencyWillRaiseNotifyEvent(ProductEditorViewModel sut, string currency)
 {
     // Fixture setup
     // Exercise system and verify outcome
     sut.ShouldNotifyOn(s => s.Currency).When(s => s.Currency =  currency);
     // Teardown
 }
コード例 #35
0
 public void ChangingPriceWillRaiseNotifyEvent(ProductEditorViewModel sut, string price)
 {
     // Fixture setup
     // Exercise system and verify outcome
     sut.ShouldNotifyOn(s => s.Price).When(s => s.Price = price);
     // Teardown
 }
コード例 #36
0
 public void NotChangingTitleWillNotRaiseNotifyEvent(ProductEditorViewModel sut)
 {
     // Fixture setup
     // Exercise system and verify outcome
     sut.ShouldNotNotifyOn(s => s.Title).When(s => s.Title = s.Title);
     // Teardown
 }
コード例 #37
0
 public void UpdateProduct(ProductEditorViewModel product)
 {
     throw new NotImplementedException();
 }
コード例 #38
0
 public void InsertProduct(ProductEditorViewModel product)
 {
     this.breaker.Execute(() => 
         this.innerAgent.InsertProduct(product));
 }