public RegistrationController(ICustomerManagementService customerManagementService, IAddressManagementService addressManagementService, IMailService mailService) { _customerManagementService = customerManagementService; _addressManagementService = addressManagementService; _mailService = mailService; }
/// <summary> /// <see cref="Microsoft.Samples.NLayerApp.DistributedServices.MainModule.IMainModuleService"/> /// </summary> /// <param name="customer"><see cref="Microsoft.Samples.NLayerApp.DistributedServices.MainModule.IMainModuleService"/></param> public void ChangeCustomer(Customer customer) { try { //Resolve root dependency and perform operation using (ICustomerManagementService customerService = IoCFactory.Instance.CurrentContainer.Resolve <ICustomerManagementService>()) { customerService.ChangeCustomer(customer); } } catch (ArgumentNullException ex) { //trace data for internal health system and return specific FaultException here! //Log and throw is a knowed anti-pattern but in this point ( entry point for clients this is admited!) //log exception for manage health system ITraceManager traceManager = IoCFactory.Instance.CurrentContainer.Resolve <ITraceManager>(); traceManager.TraceError(ex.Message); //propagate exception to client ServiceError detailedError = new ServiceError() { ErrorMessage = Resources.Messages.exception_InvalidArguments }; throw new FaultException <ServiceError>(detailedError); } }
public void AddCustomer_Invoke_Test() { //Arrange ICustomerManagementService customerService = IoCFactory.Instance.CurrentContainer.Resolve <ICustomerManagementService>(); string newCustomerCode = "C0001"; Customer customer = new Customer() { CustomerCode = newCustomerCode, ContactName = "Test", CountryId = 1, CompanyName = "Unit test", Address = new AddressInformation() { Address = "address2", City = "Madrid", Fax = "+340010001", Telephone = "+340010001" }, IsEnabled = true, CustomerPicture = new CustomerPicture() { Photo = null } }; //Act customerService.AddCustomer(customer); Customer inStorage = customerService.FindCustomerByCode(newCustomerCode); //Assert Assert.IsNotNull(inStorage); }
/// <summary> /// <see cref="Microsoft.Samples.NLayerApp.DistributedServices.MainModule.IMainModuleService"/> /// </summary> /// <param name="customerCode"><see cref="Microsoft.Samples.NLayerApp.DistributedServices.MainModule.IMainModuleService"/></param> /// <returns><see cref="Microsoft.Samples.NLayerApp.DistributedServices.MainModule.IMainModuleService"/></returns> public Customer GetCustomerByCode(string customerCode) { try { ICustomerManagementService customerService = IoCFactory.Instance.CurrentContainer.Resolve <ICustomerManagementService>(); return(customerService.FindCustomerByCode(customerCode)); } catch (ArgumentNullException ex) { //trace data for internal health system and return specific FaultException here! //Log and throw is a knowed anti-pattern but in this point ( entry point for clients this is admited!) //log exception for manage health system ITraceManager traceManager = IoCFactory.Instance.CurrentContainer.Resolve <ITraceManager>(); traceManager.TraceError(ex.Message); //propagate exception to client ServiceError detailedError = new ServiceError() { ErrorMessage = Resources.Messages.exception_InvalidArguments }; throw new FaultException <ServiceError>(detailedError); } }
public WantedController(ICustomerManagementService customerManagementService, IAddressManagementService addressManagementService, IWantedUserManagementService wantedUserManagementService) { _customerManagementService = customerManagementService; _addressManagementService = addressManagementService; _wantedUserManagementService = wantedUserManagementService; }
public void AddCustomer_Invoke_NullItemThrowArgumentNullException_Test() { //Arrange ICustomerManagementService customerService = IoCFactory.Instance.CurrentContainer.Resolve <ICustomerManagementService>(); customerService.AddCustomer(null); }
public RegistrationController(ICustomerManagementService customerManagementService, IAddressManagementService addressManagementService, IMailService mailService) { _customerManagementService = customerManagementService; _addressManagementService = addressManagementService; _mailService = mailService; }
public NewsletterService(ICustomerManagementService customerManagementService) { // Subscribe to the event of another service of the distributed app. customerManagementService.CustomerRegistered += OnCustomerRegistered; // In a real cloud application, the pub-sub shoud be configured // externally in addition to this runtime declaration. }
/// <summary> /// <see cref="Microsoft.Samples.NLayerApp.DistributedServices.MainModule.IMainModuleService"/> /// </summary> /// <param name="pagedCriteria"><see cref="Microsoft.Samples.NLayerApp.DistributedServices.MainModule.IMainModuleService"/></param> /// <returns><see cref="Microsoft.Samples.NLayerApp.DistributedServices.MainModule.IMainModuleService"/></returns> public List <Country> GetPagedCountries(PagedCriteria pagedCriteria) { try { //Resolve root dependencies and perform operations using (ICustomerManagementService customerService = IoCFactory.Instance.CurrentContainer.Resolve <ICustomerManagementService>()) { return(customerService.FindPagedCountries(pagedCriteria.PageIndex, pagedCriteria.PageCount)); } } catch (ArgumentException ex) { //trace data for internal health system and return specific FaultException here! //Log and throw is a knowed anti-pattern but in this point ( entry point for clients this is admited!) //log exception for manage health system ITraceManager traceManager = IoCFactory.Instance.CurrentContainer.Resolve <ITraceManager>(); traceManager.TraceError(ex.Message); //propagate exception to client ServiceError detailedError = new ServiceError() { ErrorMessage = Resources.Messages.exception_InvalidArguments }; throw new FaultException <ServiceError>(detailedError); } }
public void FindPagedCustomers_Invoke_NullPageCountThrowArgumentException_Test() { //Arrange ICustomerManagementService customerService = IoCFactory.Instance.CurrentContainer.Resolve <ICustomerManagementService>(); //Act List <Customer> customers = customerService.FindPagedCustomers(0, 0); }
public void ChangeCustomer_Invoke_NullItemThrowNewArgumentNullException_Test() { //Arrange using (ICustomerManagementService customerService = IoCFactory.Instance.CurrentContainer.Resolve <ICustomerManagementService>()) { //Act customerService.ChangeCustomer(null); } }
public void DeleteCustomer_Invoke_NullCustomerThrowArgumentNullException_Test() { //Arrange ICustomerManagementService customerService = IoCFactory.Instance.CurrentContainer.Resolve <ICustomerManagementService>(); Customer randomCustomer = null; //Act customerService.RemoveCustomer(randomCustomer); }
public void ChangeCustomer_Invoke_Test() { //Arrange ICustomerManagementService customerService = IoCFactory.Instance.CurrentContainer.Resolve <ICustomerManagementService>(); string customerCode = "A0004"; Customer customer = customerService.FindCustomerByCode(customerCode); //Act customer.ContactName = "Set new customer name"; customerService.ChangeCustomer(customer); }
public void FindCustomerByCode_Invoke_Test() { //Arrange ICustomerManagementService customerService = IoCFactory.Instance.CurrentContainer.Resolve <ICustomerManagementService>(); string customerCode = "A0004"; //Act Customer customer = customerService.FindCustomerByCode(customerCode); //Assert Assert.IsNotNull(customer); Assert.AreEqual(customer.CustomerCode, customerCode); }
public void FindPagedCustomer_Invoke_Test() { //Arrange ICustomerManagementService customerService = IoCFactory.Instance.CurrentContainer.Resolve <ICustomerManagementService>(); int pageIndex = 0; int pageCount = 1; //Act List <Customer> customers = customerService.FindPagedCustomers(pageIndex, pageCount); //Assert Assert.IsNotNull(customers); customers.ForEach(c => Assert.IsTrue(c.IsEnabled)); }
public async Task GetBadRequestIfGetCustomerCallDoesNotContainValidGuidAsCustomerIdAsync() { // Arrange ICustomerManagementService customerManagementService = A.Fake <ICustomerManagementService>(); ILogger logger = A.Fake <ILogger>(); var sut = new CustomerManagementFunctions(customerManagementService); var httpContext = new DefaultHttpContext(); var httpRequest = new DefaultHttpRequest(httpContext); // Act IActionResult actual = await sut.GetCustomerAsync(httpRequest, "123434", logger); // Assert Assert.Equal(HttpStatusCode.BadRequest, (HttpStatusCode)((ObjectResult)actual).StatusCode); }
public async Task ThrowsExceptionWhenBodyIsNotCorrectFormatAsync() { // Arrange ICustomerManagementService customerManagementService = A.Fake <ICustomerManagementService>(); ILogger logger = A.Fake <ILogger>(); var sut = new CustomerManagementFunctions(customerManagementService); var httpContext = new DefaultHttpContext(); var httpRequest = new DefaultHttpRequest(httpContext) { Body = new MemoryStream(Encoding.UTF8.GetBytes("NotCorrectFormat")) }; A.CallTo(() => customerManagementService.StoreCustomerInformationAsync(TestHelper.CustomerId)) .Returns(TestHelper.GetCustomerInfoWithTestHelperDefaultValues()); // Act & Assert await Assert.ThrowsAsync <JsonReaderException>(() => sut.StoreCustomerAsync(httpRequest)); }
public async Task BeGetBadRequestWhenStoreCustomerIsCalledWithoutBodyAsync() { // Arrange ICustomerManagementService customerManagementService = A.Fake <ICustomerManagementService>(); ILogger logger = A.Fake <ILogger>(); var sut = new CustomerManagementFunctions(customerManagementService); var httpContext = new DefaultHttpContext(); var httpRequest = new DefaultHttpRequest(httpContext); A.CallTo(() => customerManagementService.StoreCustomerInformationAsync(TestHelper.CustomerId)) .Returns(TestHelper.GetCustomerInfoWithTestHelperDefaultValues()); // Act IActionResult actual = await sut.StoreCustomerAsync(httpRequest); // Assert Assert.Equal(HttpStatusCode.BadRequest, (HttpStatusCode)((StatusCodeResult)actual).StatusCode); }
public void DeleteCustomer_Invoke_Test() { //Arrange ICustomerManagementService customerService = IoCFactory.Instance.CurrentContainer.Resolve <ICustomerManagementService>(); Customer randomCustomer = null; //Act randomCustomer = customerService.FindCustomerByCode("A0001"); customerService.RemoveCustomer(randomCustomer); //Assert Customer removedCustomer = customerService.FindCustomerByCode("A0001"); Assert.IsNull(removedCustomer); }
public async Task BeAbleToGetCustomerAsync() { // Arrange ICustomerManagementService customerManagementService = A.Fake <ICustomerManagementService>(); ILogger logger = A.Fake <ILogger>(); var sut = new CustomerManagementFunctions(customerManagementService); var httpContext = new DefaultHttpContext(); var httpRequest = new DefaultHttpRequest(httpContext); A.CallTo(() => customerManagementService.GetCustomerInformationAsync(TestHelper.CustomerId)) .Returns(TestHelper.GetCustomerInfoWithTestHelperDefaultValues()); // Act IActionResult actual = await sut.GetCustomerAsync(httpRequest, TestHelper.CustomerId.ToString(), logger); // Assert Assert.Equal(HttpStatusCode.OK, (HttpStatusCode)((ObjectResult)actual).StatusCode); Assert.Equal(TestHelper.GetCustomerInfoWithTestHelperDefaultValues().CustomerId, ((CustomerInfo)((ObjectResult)actual).Value).CustomerId); Assert.Equal(TestHelper.GetCustomerInfoWithTestHelperDefaultValues().TenantId, ((CustomerInfo)((ObjectResult)actual).Value).TenantId); }
public async Task GetBadResultWhenCustomerInfoObjectIsNullAsync() { // Arrange ICustomerManagementService customerManagementService = A.Fake <ICustomerManagementService>(); ILogger logger = A.Fake <ILogger>(); var sut = new CustomerManagementFunctions(customerManagementService); var httpContext = new DefaultHttpContext(); var httpRequest = new DefaultHttpRequest(httpContext) { Body = new MemoryStream(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(TestHelper.GetStoreCustomerWithTestHelperDefaultValues()))) }; A.CallTo(() => customerManagementService.StoreCustomerInformationAsync(TestHelper.CustomerId)) .Returns <CustomerInfo>(null); // Act IActionResult actual = await sut.StoreCustomerAsync(httpRequest); // Assert Assert.Equal(HttpStatusCode.BadRequest, (HttpStatusCode)((StatusCodeResult)actual).StatusCode); }
public CustomerManagementFunctions(ICustomerManagementService customerManagementService) { _customerManagementService = customerManagementService; }
public ContactController(ICustomerManagementService service) { this.service = service; }
public NewsletterService(ICustomerManagementService customerManagementService) { // !!! LOOK HERE !!! // Subscribe to the event of another service of the distributed app. customerManagementService.CustomerRegistered += OnCustomerRegistered; }
public RewardProgramService(ICustomerManagementService customerManagementService) { customerManagementService.CustomerRegistered += OnCustomerRegistered; }
public CustomerController() { _service = ServiceLocatorFactory.GetServiceLocator().GetService<ICustomerManagementService>(); }
public ThankYouController(ICustomerManagementService customerManagementService) { _customerManagementService = customerManagementService; }
public VotingProfileController(ICustomerManagementService customerManagementService, IWantedUserManagementService wantedUserManagementService) { _customerManagementService = customerManagementService; _wantedUserManagementService = wantedUserManagementService; }
public CustomersController(ICustomerManagementService customerManagementService) { _customerService = customerManagementService; }
/// <summary> /// Initializes a new instance of the <see cref="CustomerController"/> class. /// </summary> /// <param name="customerService">The customer service.</param> public CustomerController(ICustomerManagementService customerService) { _CustomerService = customerService; }
public ContestRESTAPIController(IContestEntryManagementService contestEntryManagementService, ICustomerManagementService customerManagementService) { _contestEntryManagementService = contestEntryManagementService; _customerManagementService = customerManagementService; }