public void When_UpsertCustomerContactData_andEmailAlreadyExists_throw_EmailAddressAlreadyExistsException() { var client = Substitute.For <IRestClient>(); client.LastResponse.Returns(new RestClient.APIResponse(new HttpResponseMessage(HttpStatusCode.Accepted)) { IsSuccess = false, Content = "Contact with Email Address [email protected] already exists" }); _dssService = new DssService(client, Options.Create(new DssSettings() { ApiKey = "9238dfjsjdsidfs83fds", CustomerApiUrl = "https://this.is.anApi.org.uk", AccountsTouchpointId = "9000000001", CustomerApiVersion = "V1", DigitalIdentitiesPatchByCustomerIdApiVersion = "https://this.is.anApi.org.uk", DigitalIdentitiesPatchByCustomerIdApiUrl = "https://this.is.anApi.org.uk", CustomerContactDetailsApiUrl = "https://this.is.anApi.org.uk" }), _logger); Assert.ThrowsAsync <EmailAddressAlreadyExistsException>(() => _dssService.UpsertCustomerContactData( new Customer { Contact = new Contact { ContactId = Guid.NewGuid().ToString(), EmailAddress = "*****@*****.**" }, })); }
public async Task When_UpsertCustomerContactData_ForExistingContactDetails_ReturnOk() { var client = Substitute.For <IRestClient>(); client.LastResponse.Returns(new RestClient.APIResponse(new HttpResponseMessage(HttpStatusCode.Accepted)) { IsSuccess = true, Content = string.Empty, }); _dssService = new DssService(client, Options.Create(new DssSettings() { ApiKey = "9238dfjsjdsidfs83fds", CustomerApiUrl = "https://this.is.anApi.org.uk", AccountsTouchpointId = "9000000001", CustomerApiVersion = "V1", DigitalIdentitiesPatchByCustomerIdApiVersion = "https://this.is.anApi.org.uk", DigitalIdentitiesPatchByCustomerIdApiUrl = "https://this.is.anApi.org.uk", CustomerContactDetailsApiUrl = "https://this.is.anApi.org.uk" }), _logger); await _dssService.UpsertCustomerContactData(new Customer { Contact = new Contact { ContactId = Guid.NewGuid().ToString(), }, }); await client.Received(1).PatchAsync <object>(Arg.Any <string>(), Arg.Any <HttpRequestMessage>()); }
public void Init() { Logger = Substitute.For <ILogger <DssService> >(); var mockHandler = DssHelpers.GetMockMessageHandler(DssHelpers.SuccessfulUpdateActionPlan(), statusToReturn: HttpStatusCode.Created); RestClient = new RestClient(mockHandler.Object); DssSettings = Options.Create(new DssSettings() { ApiKey = "9238dfjsjdsidfs83fds", SessionApiUrl = "https://this.is.anApi.org.uk", CustomerApiVersion = "V3", CustomerApiUrl = "https://this.is.anApi.org.uk", SessionApiVersion = "V3", GoalsApiUrl = "https://this.is.anApi.org.uk", GoalsApiVersion = "V2", ActionsApiUrl = "https://this.is.anApi.org.uk", ActionsApiVersion = "v3", InteractionsApiUrl = "https://this.is.anApi.org.uk", AdviserDetailsApiVersion = "v2", ActionPlansApiUrl = "https://this.is.anApi.org.uk", ActionPlansApiVersion = "v2", AdviserDetailsApiUrl = "https://this.is.anApi.org.uk", TouchpointId = "9000000001" }); _dssWriter = new DssService(RestClient, DssSettings, Logger); updateActionPlan = new ActionPlans.Services.DSS.Models.UpdateActionPlan() { CustomerId = new Guid(), InteractionId = new Guid(), ActionPlanId = new Guid(), DateActionPlanAcknowledged = DateTime.Now }; }
public EditYourDetailsController(IOptions <CompositeSettings> compositeSettings, IAuthService authService, IDssReader dssReader, IDssWriter dssWriter, IDocumentService <CmsApiSharedContentModel> documentService, IConfiguration config) : base(compositeSettings, authService, documentService, config) { _dssReader = dssReader; _dssWriter = dssWriter; }
public ChangeGoalStatusController(ILogger <ChangeGoalStatusController> logger, IOptions <CompositeSettings> compositeSettings, IDssReader dssReader, IDssWriter dssWriter, ICosmosService cosmosServiceService, IDocumentService <CmsApiSharedContentModel> documentService, IConfiguration config) : base(compositeSettings, dssReader, cosmosServiceService, documentService, config) { _dssWriter = dssWriter; _dssReader = dssReader; ViewModel.GeneratePageTitle("Change goal status"); }
public async Task When_UpdateLastLoginWithException_UpdateCustomer() { _dssService = new DssService(_restClient, _dssSettings, _logger); var token = "test"; var result = await _dssService.UpdateLastLogin(new Guid(), token); result.Should().NotBe(null); }
public HomeController(ILogger <HomeController> logger, IOptions <CompositeSettings> compositeSettings, IDssReader dssReader, IDssWriter dssWriter, ICosmosService cosmosServiceService, IOptions <AuthSettings> authSettings, IDocumentService <CmsApiSharedContentModel> documentService, IConfiguration config) : base(compositeSettings, dssReader, cosmosServiceService, documentService, config) { _dssReader = dssReader; _dssWriter = dssWriter; _authSettings = authSettings; _logger = logger; _sharedContent = config.GetValue <Guid>(Constants.SharedContentGuidConfig); _documentService = documentService; }
public async Task IfCustomerIsNull_ReturnNull() { _dssService = new DssService(Options.Create(new DssSettings() { ApiKey = "9238dfjsjdsidfs83fds", CustomerApiUrl = "https://this.is.anApi.org.uk", AccountsTouchpointId = "9000000001", CustomerApiVersion = "V1" }), _logger); var result = await _dssService.CreateCustomerData(null); result.Should().BeNull(); }
public async Task When_UpdateGoalNoSuccess_Throw_Exception() { var restClient = Substitute.For <IRestClient>(); restClient.LastResponse = new RestClient.APIResponse(new HttpResponseMessage(HttpStatusCode.NoContent)) { IsSuccess = false }; _dssWriter = new DssService(restClient, DssSettings, Logger); _dssWriter.Invoking(sut => sut.UpdateAction(updateAction)) .Should().Throw <DssException>(); }
public async Task When_UpdateLastLoginWithException_Return_Exception() { var restClient = Substitute.For <IRestClient>(); restClient.LastResponse = new RestClient.APIResponse(new HttpResponseMessage(HttpStatusCode.Unauthorized)); var token = "test"; restClient.GetAsync <string>(Arg.Any <string>(), Arg.Any <HttpRequestMessage>()).Returns <string>(x => { throw new DssException("Customer"); }); _dssService = new DssService(restClient, _dssSettings, _logger); _dssService.Invoking(async sut => await sut.UpdateLastLogin(new Guid(), token)) .Should().Throw <DssException>(); }
public void Setup() { _logger = Substitute.For <ILogger <DssService> >(); var mockHandler = DssHelpers.GetMockMessageHandler(DssHelpers.SuccessfulDssCustomerCreation(), statusToReturn: HttpStatusCode.Created); _restClient = new RestClient(mockHandler.Object); _dssService = new DssService(_restClient, Options.Create(new DssSettings() { ApiKey = "9238dfjsjdsidfs83fds", CustomerApiUrl = "https://this.is.anApi.org.uk", AccountsTouchpointId = "9000000001", CustomerApiVersion = "V1" }), _logger); }
public void Init() { _documentService = Substitute.For <IDocumentService <CmsApiSharedContentModel> >(); var inMemorySettings = new Dictionary <string, string> { { Constants.SharedContentGuidConfig, Guid.NewGuid().ToString() } }; _config = new ConfigurationBuilder() .AddInMemoryCollection(inMemorySettings) .Build(); _compositeSettings = Options.Create(new CompositeSettings()); _authService = Substitute.For <IAuthService>(); _dssService = Substitute.For <IDssWriter>(); }
public async Task When_DeleteCustomerSuccess_ReturnOk() { var mockHandler = DssHelpers.GetMockMessageHandler(DssHelpers.SuccessfulDssCustomerCreation(), statusToReturn: HttpStatusCode.OK); _restClient = new RestClient(mockHandler.Object); _dssService = new DssService(_restClient, Options.Create(new DssSettings() { ApiKey = "9238dfjsjdsidfs83fds", CustomerApiUrl = "https://this.is.anApi.org.uk", AccountsTouchpointId = "9000000001", CustomerApiVersion = "V1", DigitalIdentitiesPatchByCustomerIdApiVersion = "https://this.is.anApi.org.uk", DigitalIdentitiesPatchByCustomerIdApiUrl = "https://this.is.anApi.org.uk", }), _logger); await _dssService.DeleteCustomer(Guid.NewGuid()); }
public void When_DeleteCustomerRequestEmptyGuid_ThrowException() { var mockHandler = DssHelpers.GetMockMessageHandler(DssHelpers.SuccessfulDssCustomerCreation(), statusToReturn: HttpStatusCode.InternalServerError); _restClient = new RestClient(mockHandler.Object); _dssService = new DssService(_restClient, Options.Create(new DssSettings() { ApiKey = "9238dfjsjdsidfs83fds", CustomerApiUrl = "https://this.is.anApi.org.uk", AccountsTouchpointId = "9000000001", CustomerApiVersion = "V1" }), _logger); _dssService.Invoking(x => x.DeleteCustomer(Guid.Empty)).Should() .Throw <UnableToUpdateCustomerDetailsException>(); }
public async Task When_UpdateGoalErrors_Throw_Exception() { var restClient = Substitute.For <IRestClient>(); restClient.LastResponse = new RestClient.APIResponse(new HttpResponseMessage(HttpStatusCode.NoContent)) { IsSuccess = false }; _dssWriter = new DssService(restClient, DssSettings, Logger); restClient.PatchAsync <Goal>(Arg.Any <string>(), Arg.Any <HttpRequestMessage>()) .ThrowsForAnyArgs <Exception>(); _dssWriter.Invoking(sut => sut.UpdateAction(updateAction)) .Should().Throw <DssException>(); Logger.ReceivedCalls().Count().Equals(1); }
public async Task IfApiCallIsUnSuccessful_ReturnNull() { var mockHandler = DssHelpers.GetMockMessageHandler(DssHelpers.SuccessfulDssCustomerCreation(), statusToReturn: HttpStatusCode.InternalServerError); _restClient = new RestClient(mockHandler.Object); _dssService = new DssService(_restClient, Options.Create(new DssSettings() { ApiKey = "9238dfjsjdsidfs83fds", CustomerApiUrl = "https://this.is.anApi.org.uk", AccountsTouchpointId = "9000000001", CustomerApiVersion = "V1" }), _logger); var result = await _dssService.CreateCustomerData(new Customer()); result.Should().BeNull(); }
public void SetupBase() { user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, "example name"), new Claim(ClaimTypes.NameIdentifier, "1"), new Claim("CustomerId", new Guid().ToString()), }, "mock")); _compositeSettings = Options.Create(new CompositeSettings { Cdn = "cdn", Path = "Path" }); _dssReader = Substitute.For <IDssReader>(); _dssWriter = Substitute.For <IDssWriter>(); _cosmosService = Substitute.For <ICosmosService>(); _authSettings = Options.Create(new AuthSettings { }); var customer = new Customer { CustomerId = new Guid("c2e27821-cc60-4d3d-b4f0-cbe20867897c"), FamilyName = "familyName", GivenName = "givenName" }; var adviser = new Adviser { AdviserDetailId = new Guid().ToString(), AdviserName = null, AdviserEmailAddress = null, AdviserContactNumber = null, LastModifiedDate = default,
public AuthSuccess(IOptions <CompositeSettings> compositeSettings, IAuthService authService, IDssWriter dssWriter, IDocumentService <CmsApiSharedContentModel> documentService, IConfiguration config) : base(compositeSettings, authService, documentService, config) { _dssWriter = dssWriter; }
public DeleteAccountController(IOptions <CompositeSettings> compositeSettings, IDssWriter dssService, IAuthService authService, IDocumentService <CmsApiSharedContentModel> documentService, IConfiguration config) : base(compositeSettings, authService, documentService, config) { _dssService = dssService; }