Created
January 4, 2011 13:31
-
-
Save jfromaniello/764760 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Test | |
[TestMethod] | |
public void CanLookupForManufacturerWhenChangingTheManufacturerCode() | |
{ | |
var backend = new Mock<IBackend>(); | |
backend.Setup(be => be.SendAndReceive<GetEntityResponse<CustomerDetailsDto>>(It.Is<GetCustomerByCodeRequest>(re => re.Code == "123"))) | |
.Returns(new GetEntityResponse<CustomerDetailsDto> { Entity = new CustomerDetailsDto { CodeFld = "123", Name = "Tito Fuentes", Id = 123 } }); | |
var editViewModel = new EditArticleViewModel | |
{ | |
Backend = backend.Object, | |
Mapper = MapperHelper.Create(), | |
EventPublisher = Mock.Of<IEventPublisher>(), | |
Parent = Mock.Of<IConductor>(), | |
InteractionService = Mock.Of<IInteractionService>() | |
}; | |
//act | |
editViewModel.ManufacturerCode = "123"; | |
editViewModel.Satisfy( vm => vm.ManufacturerName == "Tito Fuentes" | |
&& vm.ManufacturerCode == "123" | |
&& vm.ManufacturerId == 123); | |
} | |
//Implementation | |
public string ManufacturerCode | |
{ | |
get { return manufacturerCode; } | |
set | |
{ | |
manufacturerCode = value; | |
NotifyOfPropertyChange(() => ManufacturerCode); | |
if (isLoadingData) return; | |
Execute.OnBackgroundThread(ReloadManufacturer); | |
} | |
} | |
private void ReloadManufacturer() | |
{ | |
if (string.IsNullOrEmpty(ManufacturerCode)) | |
{ | |
ManufacturerId = 0; | |
manufacturerName = string.Empty; | |
return; | |
} | |
var request = new GetCustomerByCodeRequest { Code = ManufacturerCode }; | |
var response = Backend.SendAndReceive<GetEntityResponse<CustomerDetailsDto>>(request); | |
if (response == null || response.Entity == null) | |
{ | |
InteractionService.Info("Articles","The manufacturer code entered is invalid."); | |
return; | |
} | |
ManufacturerId = response.Entity.Id; | |
ManufacturerName = response.Entity.Name; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment