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 AltranController_GetPoliciesByName_ExistingClientNameWithoutPolicies_ReturnsNoContentResult() { //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>(); 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 Assert.IsInstanceOfType(actionResult.Result, typeof(NoContentResult)); }
public void ClientsRepository_GetClientByName_NonExistingName_ReturnsNullClient() { //Arrange string url = ArrangeProvider._URL_; var client = ArrangeProvider.GetClient(name: ArrangeProvider._NAME_); var json = JsonConvert.SerializeObject(ArrangeProvider.GetRootClient(client), Formatting.Indented); var options = ArrangeProvider.GetResourcesUrlOption(url, url); var httpClient = ArrangeProvider.GetMockJsonHttpClient(url, json); var clientsRepository = new ClientsRepository(options, httpClient); //Act var result = clientsRepository.GetClientByName(ArrangeProvider._NAME2_); //Assert Assert.IsNull(result); }
public void ClientsRepository_GetClientById_ExistingId_ReturnsClient() { //Arrange string url = ArrangeProvider._URL_; var client = ArrangeProvider.GetClient(id: ArrangeProvider._ID1_); var json = JsonConvert.SerializeObject(ArrangeProvider.GetRootClient(client), Formatting.Indented); var options = ArrangeProvider.GetResourcesUrlOption(url, url); var httpClient = ArrangeProvider.GetMockJsonHttpClient(url, json); var clientsRepository = new ClientsRepository(options, httpClient); //Act var result = clientsRepository.GetClientById(ArrangeProvider._ID1_); //Assert Assert.AreEqual(client, result); }
public void ClientsService_GetClientById_NonExistingId_ReturnsNull() { //Arrange string id = ArrangeProvider._ID1_; Client client = ArrangeProvider.GetClient(id: id); var mockRepo = new Mock <IClientsRepository>(); mockRepo.Setup(x => x.GetClientById(id)).Returns(client); var options = ArrangeProvider.GetAppSettingslOption(); var mapper = ArrangeProvider.GetMapper(); var service = new ClientsService(options, mapper, mockRepo.Object); //Act var result = service.GetClientById(ArrangeProvider._ID0_); //Assert Assert.IsNull(result); }
public void ClientsService_GetClientByName_NonExistingName_ReturnsNull() { //Arrange string name = ArrangeProvider._NAME_; Client client = ArrangeProvider.GetClient(email: name); var mockRepo = new Mock <IClientsRepository>(); mockRepo.Setup(x => x.GetClientByName(name)).Returns(client); var options = ArrangeProvider.GetAppSettingslOption(); var mapper = ArrangeProvider.GetMapper(); var service = new ClientsService(options, mapper, mockRepo.Object); //Act var result = service.GetClientByName(ArrangeProvider._NAME2_); //Assert Assert.IsNull(result); }
public void ClientsService_Authenticate_NonExistingEmail_ReturnsNull() { //Arrange string email = ArrangeProvider._EMAIL_; Client client = ArrangeProvider.GetClient(id: email); var mockRepo = new Mock <IClientsRepository>(); mockRepo.Setup(x => x.GetClientByEmail(email)).Returns(client); var options = ArrangeProvider.GetAppSettingslOption(); var mapper = ArrangeProvider.GetMapper(); var service = new ClientsService(options, mapper, mockRepo.Object); //Act var result = service.Authenticate(ArrangeProvider._EMAIL2_); //Assert Assert.IsNull(result); }
public void AltranController_GetClientByName_NonExistingClientName_ReturnsNoContentResult() { //Arrange var mapper = ArrangeProvider.GetMapper(); var name = ArrangeProvider._NAME_; var clientDto = mapper.Map <ClientDto>(ArrangeProvider.GetClient(name: name)); var mockClientService = new Mock <IClientsService>(); mockClientService.Setup(x => x.GetClientByName(name)).Returns(clientDto); var mockPolicyService = new Mock <IPoliciesService>(); var controller = new AltranController(mockClientService.Object, mockPolicyService.Object); // Act var actionResult = controller.GetClientByName(ArrangeProvider._NAME2_); //Assert Assert.IsInstanceOfType(actionResult.Result, typeof(NoContentResult)); }
public void ClientsService_Authenticate_ExistingEmailAndSpecificRole_ReturnsValidJWDTokenWithSameRole() { //Arrange string email = ArrangeProvider._EMAIL_; string role = Role.Admin; Client client = ArrangeProvider.GetClient(id: email, role: role); var mockRepo = new Mock <IClientsRepository>(); mockRepo.Setup(x => x.GetClientByEmail(email)).Returns(client); var options = ArrangeProvider.GetAppSettingslOption(); var mapper = ArrangeProvider.GetMapper(); var service = new ClientsService(options, mapper, mockRepo.Object); //Act var result = service.Authenticate(ArrangeProvider._EMAIL_); //Assert Assert.AreEqual(role, result.Role); }
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 AltranController_GetClientByName_ExistingClientName_ReturnsClient() { //Arrange var mapper = ArrangeProvider.GetMapper(); var name = ArrangeProvider._NAME_; var clientDto = mapper.Map <ClientDto>(ArrangeProvider.GetClient(name: name)); var mockClientService = new Mock <IClientsService>(); mockClientService.Setup(x => x.GetClientByName(name)).Returns(clientDto); var mockPolicyService = new Mock <IPoliciesService>(); var controller = new AltranController(mockClientService.Object, mockPolicyService.Object); // Act var actionResult = controller.GetClientByName(name); //Assert var result = actionResult.Result as OkObjectResult; Assert.IsNotNull(result); Assert.AreEqual(clientDto, result.Value); }