public void PoliciesService_GetPoliciesByClientId_ExistingClientIdWithPolicies_ReturnPolicies() { //Arrange var id = ArrangeProvider._ID0_; var email = ArrangeProvider._EMAIL_; var rootPolicy = ArrangeProvider.GetRootPolicy(); rootPolicy.Policies.Add(ArrangeProvider.GetPolicy("1", email, id, 1.1)); rootPolicy.Policies.Add(ArrangeProvider.GetPolicy("2", email, id, 2.2)); rootPolicy.Policies.Add(ArrangeProvider.GetPolicy("3", email, id, 3.3)); var mockPoliciesRepository = new Mock <IPoliciesRepository>(); mockPoliciesRepository.Setup(x => x.GetPoliciesByClientId(id)).Returns(rootPolicy.Policies); var mapper = ArrangeProvider.GetMapper(); var service = new PoliciesService(mapper, mockPoliciesRepository.Object); var expected = rootPolicy.Policies.Select(p => mapper.Map <PolicyDto>(p)).ToList(); //Act var result = service.GetPoliciesByClientId(id); //Assert CollectionAssert.AreEquivalent((System.Collections.ICollection)(expected), (System.Collections.ICollection)result); }
public void PoliciesService_GetPoliciesByClientId_NonExistingClientId_ReturnNull() { //Arrange var id = ArrangeProvider._ID0_; var email = ArrangeProvider._EMAIL_; var rootPolicy = ArrangeProvider.GetRootPolicy(); rootPolicy.Policies.Add(ArrangeProvider.GetPolicy("1", email, id, 1.1)); rootPolicy.Policies.Add(ArrangeProvider.GetPolicy("2", email, id, 2.2)); rootPolicy.Policies.Add(ArrangeProvider.GetPolicy("3", email, id, 3.3)); var mockPoliciesRepository = new Mock <IPoliciesRepository>(); mockPoliciesRepository.Setup(x => x.GetPoliciesByClientId(id)).Returns(rootPolicy.Policies); var mapper = ArrangeProvider.GetMapper(); var service = new PoliciesService(mapper, mockPoliciesRepository.Object); //Act var result = service.GetPoliciesByClientId(ArrangeProvider._ID1_); //Assert Assert.IsTrue(result.Count() == 0); }
public void AltranController_GetClientPolicyById_NonExistingClientForPolicyId_ReturnsNoContentResult() { //Arrange var mapper = ArrangeProvider.GetMapper(); var id = ArrangeProvider._ID0_; var mockClientService = new Mock <IClientsService>(); Policy policy = ArrangeProvider.GetPolicy(id: id); var policyDto = mapper.Map <PolicyDto>(policy); var mockPolicyService = new Mock <IPoliciesService>(); mockPolicyService.Setup(x => x.GetPolicyById(id)).Returns(policyDto); var controller = new AltranController(mockClientService.Object, mockPolicyService.Object); // Act var actionResult = controller.GetClientPolicyById(id); //Assert Assert.IsInstanceOfType(actionResult.Result, typeof(NoContentResult)); }
public void AltranController_GetClientPolicyById_NonExistingPolicyId_ReturnsBadRequestResult() { //Arrange var mapper = ArrangeProvider.GetMapper(); var name = ArrangeProvider._NAME_; var email = ArrangeProvider._EMAIL_; var id = ArrangeProvider._ID0_; var clientDto = mapper.Map <ClientDto>(ArrangeProvider.GetClient(name: name, email: email, id: id)); var mockClientService = new Mock <IClientsService>(); mockClientService.Setup(x => x.GetClientById(id)).Returns(clientDto); Policy policy = ArrangeProvider.GetPolicy("1", email, id, 1.1); var policyDto = mapper.Map <PolicyDto>(policy); var mockPolicyService = new Mock <IPoliciesService>(); mockPolicyService.Setup(x => x.GetPolicyById(id)).Returns(policyDto); var controller = new AltranController(mockClientService.Object, mockPolicyService.Object); // Act var actionResult = controller.GetClientPolicyById(ArrangeProvider._ID1_); //Assert Assert.IsInstanceOfType(actionResult.Result, typeof(BadRequestObjectResult)); }
public void AltranController_GetClientPolicyById_ExistingPolicyId_ReturnsClient() { //Arrange var mapper = ArrangeProvider.GetMapper(); var name = ArrangeProvider._NAME_; var email = ArrangeProvider._EMAIL_; var id = ArrangeProvider._ID0_; var clientDto = mapper.Map <ClientDto>(ArrangeProvider.GetClient(name: name, email: email, id: id)); var mockClientService = new Mock <IClientsService>(); mockClientService.Setup(x => x.GetClientById(id)).Returns(clientDto); Policy policy = ArrangeProvider.GetPolicy("1", email, id, 1.1); var policyDto = mapper.Map <PolicyDto>(policy); var mockPolicyService = new Mock <IPoliciesService>(); mockPolicyService.Setup(x => x.GetPolicyById(id)).Returns(policyDto); var controller = new AltranController(mockClientService.Object, mockPolicyService.Object); // Act var actionResult = controller.GetClientPolicyById(id); //Assert var result = actionResult.Result as OkObjectResult; Assert.IsNotNull(result); Assert.AreEqual(clientDto, result.Value); }
public void PoliciesService_GetPolicyById_NonExistingExistingPolicyId_ReturnNull() { //Arrange var id = ArrangeProvider._ID0_; var policy = ArrangeProvider.GetPolicy(id: id); var mockPoliciesRepository = new Mock <IPoliciesRepository>(); mockPoliciesRepository.Setup(x => x.GetPolicyById(id)).Returns(policy); var mapper = ArrangeProvider.GetMapper(); var service = new PoliciesService(mapper, mockPoliciesRepository.Object); //Act var result = service.GetPolicyById(ArrangeProvider._ID1_); //Assert Assert.IsNull(result); }
public void AltranController_GetPoliciesByName_ExistingClientNameWithPolicies_ReturnsPolicies() { //Arrange var mapper = ArrangeProvider.GetMapper(); var name = ArrangeProvider._NAME_; var email = ArrangeProvider._EMAIL_; var id = ArrangeProvider._ID0_; var clientDto = mapper.Map <ClientDto>(ArrangeProvider.GetClient(name: name, email: email, id: id)); var mockClientService = new Mock <IClientsService>(); mockClientService.Setup(x => x.GetClientByName(name)).Returns(clientDto); List <Policy> policies = new List <Policy>(); policies.Add(ArrangeProvider.GetPolicy("1", email, id, 1.1)); policies.Add(ArrangeProvider.GetPolicy("2", email, id, 2.2)); policies.Add(ArrangeProvider.GetPolicy("3", email, id, 3.3)); var policyDtos = policies.Select(p => mapper.Map <PolicyDto>(p)).ToList(); var mockPolicyService = new Mock <IPoliciesService>(); mockPolicyService.Setup(x => x.GetPoliciesByClientId(id)).Returns(policyDtos); var controller = new AltranController(mockClientService.Object, mockPolicyService.Object); // Act var actionResult = controller.GetPoliciesByName(name); //Assert var result = actionResult.Result as OkObjectResult; Assert.IsNotNull(result); Assert.AreEqual(policyDtos, result.Value); }
public void PoliciesRepository_GetPoliciesByClientId_ExistingClientIdWithPolicies_ReturnsPolicies() { //Arrange string url = ArrangeProvider._URL_; var rootPolicy = ArrangeProvider.GetRootPolicy(); rootPolicy.Policies.Add(ArrangeProvider.GetPolicy("1", ArrangeProvider._EMAIL_, ArrangeProvider._ID1_, 1.1)); rootPolicy.Policies.Add(ArrangeProvider.GetPolicy("2", ArrangeProvider._EMAIL_, ArrangeProvider._ID1_, 2.2)); rootPolicy.Policies.Add(ArrangeProvider.GetPolicy("3", ArrangeProvider._EMAIL_, ArrangeProvider._ID1_, 3.3)); var json = JsonConvert.SerializeObject(rootPolicy, Formatting.Indented); var options = ArrangeProvider.GetResourcesUrlOption(url, url); var httpClient = ArrangeProvider.GetMockJsonHttpClient(url, json); var clientsRepository = new PoliciesRepository(options, httpClient); //Act var result = clientsRepository.GetPoliciesByClientId(ArrangeProvider._ID1_); //Assert CollectionAssert.AreEquivalent((System.Collections.ICollection)rootPolicy.Policies, (System.Collections.ICollection)result); }