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 }
// 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; } }
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)); }
public void NotChangingTitleWillNotRaiseNotifyEvent(ProductEditorViewModel sut) { // Fixture setup // Exercise system and verify outcome sut.ShouldNotNotifyOn(s => s.Title).When(s => s.Title = s.Title); // Teardown }
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 }
//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)); }
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 }
public void SettingNullCurrencyWillThrow(ProductEditorViewModel sut) { // Fixture setup // Exercise system and verify outcome Assert.Throws <ArgumentNullException>(() => sut.Currency = null); // Teardown }
public void SutIsNotifyPropertyChanged(ProductEditorViewModel sut) { // Fixture setup // Exercise system // Verify outcome Assert.IsAssignableFrom <INotifyPropertyChanged>(sut); // Teardown }
public void SettingNullNameWillThrow(ProductEditorViewModel sut) { // Fixture setup // Exercise system and verify outcome Assert.Throws<ArgumentNullException>(() => sut.Name = null); // Teardown }
public void SutIsDataErrorInfo(ProductEditorViewModel sut) { // Fixture setup // Exercise system // Verify outcome Assert.IsAssignableFrom <IDataErrorInfo>(sut); // Teardown }
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); }
public void IsValidIsFalseWhenSutIsInvalid(ProductEditorViewModel sut) { // Fixture setup // Exercise system var result = sut.IsValid; // Verify outcome Assert.False(result, "IsValid"); // Teardown }
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 }
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 }
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 }
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); } }
public void UpdateProduct(ProductEditorViewModel product) { this.breaker.Guard(); try { this.innerAgent.UpdateProduct(product); this.breaker.Succeed(); } catch (Exception e) { this.breaker.Trip(e); throw; } }
public void UpdateProduct(ProductEditorViewModel product) { try { this.innerAgent.UpdateProduct(product); } catch (CommunicationException e) { this.AlertUser(e.Message); } catch (InvalidOperationException e) { this.AlertUser(e.Message); } }
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 }
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); } }
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); }
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 }
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(); }
public void InsertProduct(ProductEditorViewModel product) { this.breaker.Execute(() => this.innerAgent.InsertProduct(product)); }
public void SutIsDataErrorInfo(ProductEditorViewModel sut) { // Fixture setup // Exercise system // Verify outcome Assert.IsAssignableFrom<IDataErrorInfo>(sut); // Teardown }
public void SutIsNotifyPropertyChanged(ProductEditorViewModel sut) { // Fixture setup // Exercise system // Verify outcome Assert.IsAssignableFrom<INotifyPropertyChanged>(sut); // Teardown }
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 }
public void UpdateProduct(ProductEditorViewModel product) { throw new NotImplementedException(); }