public async void Update_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <ITransactionStatusService, ITransactionStatusRepository>(); var model = new ApiTransactionStatusServerRequestModel(); var validatorMock = new Mock <IApiTransactionStatusServerRequestModelValidator>(); validatorMock.Setup(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiTransactionStatusServerRequestModel>())).Returns(Task.FromResult(new ValidationResult(new List <ValidationFailure>() { new ValidationFailure("text", "test") }))); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new TransactionStatus())); var service = new TransactionStatusService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALTransactionStatusMapperMock, mock.DALMapperMockFactory.DALTransactionMapperMock); UpdateResponse <ApiTransactionStatusServerResponseModel> response = await service.Update(default(int), model); response.Should().NotBeNull(); response.Success.Should().BeFalse(); validatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiTransactionStatusServerRequestModel>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <TransactionStatusUpdatedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }
public async Task Delete_ByIdTransactionStatus_Valido() { Guid id = new Guid("5E210F4F-D12B-4F85-8464-6F8740920FAA"); var service = new TransactionStatusService(_httpClient); var result = await service.DeleteByIdTransactionStatus(requestUri, id); // Assert if (result.Status == HttpStatusCode.OK) { Assert.True(result.Status == HttpStatusCode.OK, "OK"); } else { List <string> listError = new List <string>(); foreach (string error in result.Data) { listError.Add(error); } Assert.Collection(listError, item => Assert.Equal("The Guid is empty", item), item => Assert.Equal("The Guid is invalid and contains 00000000", item), item => Assert.Equal("Registro não encontrado", item) ); } }
public async Task Put_TransactionStatus_Valido() { Guid guid = new Guid("5E210F4F-D12B-4F85-8464-6F8740920FAA"); TransactionStatus transactionStatus = new TransactionStatus { Id = guid, Name = "ALTERADO..." }; var service = new TransactionStatusService(_httpClient); var result = await service.PutTransactionStatus(requestUri, transactionStatus); if (result.Status == HttpStatusCode.OK) { Assert.True(result.Status == HttpStatusCode.OK, "OK"); } else { List <string> listError = new List <string>(); foreach (string error in result.Data) { listError.Add(error); } Assert.Collection(listError, item => Assert.Equal("The Name is Required", item), item => Assert.Equal("The Name must have between 2 and 30 characters", item), item => Assert.Equal("The Guid is empty", item), item => Assert.Equal("The Guid is invalid and contains 00000000", item), item => Assert.Equal("The transaction status name has already been taken.", item) ); } }
public async Task Post_TransactionStatus_The_Guid_is_empty() { TransactionStatus transactionStatus = new TransactionStatus { Id = Guid.Empty, Name = "1" }; var service = new TransactionStatusService(_httpClient); var result = await service.PostTransactionStatus(requestUri, transactionStatus); if (result.Status == HttpStatusCode.OK) { Assert.True(result.Status == HttpStatusCode.OK, "OK"); } else { List <string> listError = new List <string>(); foreach (string error in result.Data) { listError.Add(error); } Assert.Collection(listError, item => Assert.Equal("The Name is Required", item), item => Assert.Equal("The Name must have between 2 and 30 characters", item), item => Assert.Equal("The Guid is empty", item), item => Assert.Equal("The Guid is invalid and contains 00000000", item), item => Assert.Equal("The transaction status id has already been taken.", item), item => Assert.Equal("The transaction status name has already been taken.", item) ); } }
public async Task Put_TransactionStatus_The_Name_must_have_between_2_and_30_characters() { Guid guid = new Guid("1BF784F8-7B94-47EC-9FD9-5257D83E8E7D"); TransactionStatus transactionStatus = new TransactionStatus { Id = guid, Name = "o" }; var service = new TransactionStatusService(_httpClient); var result = await service.PutTransactionStatus(requestUri, transactionStatus); if (result.Status == HttpStatusCode.OK) { Assert.True(result.Status == HttpStatusCode.OK, "OK"); } else { List <string> listError = new List <string>(); foreach (string error in result.Data) { listError.Add(error); } Assert.Collection(listError, item => Assert.Equal("The Name is Required", item), item => Assert.Equal("The Name must have between 2 and 30 characters", item), item => Assert.Equal("The Guid is empty", item), item => Assert.Equal("The Guid is invalid and contains 00000000", item), item => Assert.Equal("The transaction status name has already been taken.", item) ); } }
public async Task Get_AllTransactionStatus() { var service = new TransactionStatusService(_httpClient); var result = await service.GetAllTransactionStatuss(requestUri); // Assert Assert.False(result.Status == HttpStatusCode.BadRequest, "ERROR"); Assert.True(result.Status == HttpStatusCode.OK, "OK"); }
public async Task Get_HistorycByIdTransactionStatus() { string info = "5E210F4F-D12B-4F85-8464-6F8740920FAA"; var service = new TransactionStatusService(_httpClient); var result = await service.GetHistorycByIdTransactionStatus(requestUri, info); // Assert Assert.False(result.Status == HttpStatusCode.BadRequest, "ERROR"); Assert.True(result.Status == HttpStatusCode.OK, "OK"); }
public async Task Get_ByNameTransactionStatus() { string info = "ALTERADO..."; var service = new TransactionStatusService(_httpClient); var result = await service.GetByNameTransactionStatus(requestUri, info); // Assert Assert.False(result.Status == HttpStatusCode.BadRequest, "ERROR"); Assert.True(result.Status == HttpStatusCode.OK, "OK"); }
public static async Task <dynamic> Information() { var serviceTransactionStatus = new TransactionStatusService(_httpClient); var resultTransactionStatus = await serviceTransactionStatus.GetAllTransactionStatus(requestUri); List <TransactionStatus> statusTrans = new List <TransactionStatus>(); foreach (var item in resultTransactionStatus.Data) { statusTrans.Add(new TransactionStatus { Id = item.Id, Name = item.Name }); } return(statusTrans); }
public async void Get_ShouldReturnNullBecauseRecordNotFound() { var mock = new ServiceMockFacade <ITransactionStatusService, ITransactionStatusRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <TransactionStatus>(null)); var service = new TransactionStatusService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.TransactionStatusModelValidatorMock.Object, mock.DALMapperMockFactory.DALTransactionStatusMapperMock, mock.DALMapperMockFactory.DALTransactionMapperMock); ApiTransactionStatusServerResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void TransactionsByTransactionStatusId_Not_Exists() { var mock = new ServiceMockFacade <ITransactionStatusService, ITransactionStatusRepository>(); mock.RepositoryMock.Setup(x => x.TransactionsByTransactionStatusId(default(int), It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult <List <Transaction> >(new List <Transaction>())); var service = new TransactionStatusService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.TransactionStatusModelValidatorMock.Object, mock.DALMapperMockFactory.DALTransactionStatusMapperMock, mock.DALMapperMockFactory.DALTransactionMapperMock); List <ApiTransactionServerResponseModel> response = await service.TransactionsByTransactionStatusId(default(int)); response.Should().BeEmpty(); mock.RepositoryMock.Verify(x => x.TransactionsByTransactionStatusId(default(int), It.IsAny <int>(), It.IsAny <int>())); }
public async void All_ShouldReturnRecords() { var mock = new ServiceMockFacade <ITransactionStatusService, ITransactionStatusRepository>(); var records = new List <TransactionStatus>(); records.Add(new TransactionStatus()); mock.RepositoryMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(Task.FromResult(records)); var service = new TransactionStatusService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.TransactionStatusModelValidatorMock.Object, mock.DALMapperMockFactory.DALTransactionStatusMapperMock, mock.DALMapperMockFactory.DALTransactionMapperMock); List <ApiTransactionStatusServerResponseModel> response = await service.All(); response.Should().HaveCount(1); mock.RepositoryMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())); }
public async void Get() { var mock = new ServiceMockFacade <ITransactionStatusRepository>(); var record = new TransactionStatus(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(record)); var service = new TransactionStatusService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.TransactionStatusModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLTransactionStatusMapperMock, mock.DALMapperMockFactory.DALTransactionStatusMapperMock, mock.BOLMapperMockFactory.BOLTransactionMapperMock, mock.DALMapperMockFactory.DALTransactionMapperMock); ApiTransactionStatusResponseModel response = await service.Get(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void Create() { var mock = new ServiceMockFacade <ITransactionStatusRepository>(); var model = new ApiTransactionStatusRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <TransactionStatus>())).Returns(Task.FromResult(new TransactionStatus())); var service = new TransactionStatusService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.TransactionStatusModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLTransactionStatusMapperMock, mock.DALMapperMockFactory.DALTransactionStatusMapperMock, mock.BOLMapperMockFactory.BOLTransactionMapperMock, mock.DALMapperMockFactory.DALTransactionMapperMock); CreateResponse <ApiTransactionStatusResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.TransactionStatusModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiTransactionStatusRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <TransactionStatus>())); }
public async void Delete() { var mock = new ServiceMockFacade <ITransactionStatusRepository>(); var model = new ApiTransactionStatusRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new TransactionStatusService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.TransactionStatusModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLTransactionStatusMapperMock, mock.DALMapperMockFactory.DALTransactionStatusMapperMock, mock.BOLMapperMockFactory.BOLTransactionMapperMock, mock.DALMapperMockFactory.DALTransactionMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.TransactionStatusModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public async void Delete_NoErrorsOccurred_ShouldReturnResponse() { var mock = new ServiceMockFacade <ITransactionStatusService, ITransactionStatusRepository>(); var model = new ApiTransactionStatusServerRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new TransactionStatusService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.TransactionStatusModelValidatorMock.Object, mock.DALMapperMockFactory.DALTransactionStatusMapperMock, mock.DALMapperMockFactory.DALTransactionMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); response.Success.Should().BeTrue(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.TransactionStatusModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <TransactionStatusDeletedNotification>(), It.IsAny <CancellationToken>())); }
public async Task Post_TransactionStatus_Seed() { List <TransactionStatus> listTransactionStatus = new List <TransactionStatus>(); listTransactionStatus.Add(new TransactionStatus { Id = new Guid("9B8745FD-BDA2-41D3-8F49-8C893461FBE1"), Name = "Valor inválido" }); listTransactionStatus.Add(new TransactionStatus { Id = new Guid("47748064-E751-4E2C-93DC-E4A8FF2388BC"), Name = "Transação negada" }); listTransactionStatus.Add(new TransactionStatus { Id = new Guid("105DCD64-4498-4B06-8A74-914D1020DBE4"), Name = "Transação aprovada" }); listTransactionStatus.Add(new TransactionStatus { Id = new Guid("D5117C58-2962-4B2A-938E-05698AA76A2B"), Name = "Senha inválida" }); listTransactionStatus.Add(new TransactionStatus { Id = new Guid("FCD03359-22A7-41E3-B9DE-70F8FBA47805"), Name = "Senha Incorreta" }); listTransactionStatus.Add(new TransactionStatus { Id = new Guid("7614057A-AB4B-4447-82D5-EF88A097CBD4"), Name = "Erro no tamanho da senha" }); listTransactionStatus.Add(new TransactionStatus { Id = new Guid("D87358AF-6800-4545-BB11-A6114627DF6A"), Name = "Saldo insuficiente" }); listTransactionStatus.Add(new TransactionStatus { Id = new Guid("A92807BA-A7A8-4BFF-B198-502A26306E53"), Name = "Cartão bloqueado" }); listTransactionStatus.Add(new TransactionStatus { Id = new Guid("61F61682-65B9-424A-BB1B-7B04B3264114"), Name = "Aprovado" }); listTransactionStatus.Add(new TransactionStatus { Id = new Guid("A73D8B79-8985-4CF8-AC2C-5C4AA4B84BA5"), Name = "Registro não encontrado" }); listTransactionStatus.Add(new TransactionStatus { Id = new Guid("E23F6900-CB87-475A-9DBE-E490552967C3"), Name = "Senha entre 4 e 6 dítigos" }); listTransactionStatus.Add(new TransactionStatus { Id = new Guid("526F6B9A-2248-49AE-8119-56F03C9A9824"), Name = "Mínimo de 10 centavos" }); listTransactionStatus.Add(new TransactionStatus { Id = new Guid("7614057a-ab4b-4447-82d5-ef88a097cbd9"), Name = "Cartão vencido" }); foreach (TransactionStatus cardType in listTransactionStatus) { var service = new TransactionStatusService(_httpClient); var result = await service.PostTransactionStatus(requestUri, cardType); if (result.Status == HttpStatusCode.OK) { Assert.True(result.Status == HttpStatusCode.OK, "OK"); } else { List <string> listError = new List <string>(); foreach (string error in result.Data) { listError.Add(error); } Assert.Collection(listError, item => Assert.Equal("The Name is Required", item), item => Assert.Equal("The Name must have between 2 and 30 characters", item), item => Assert.Equal("The Guid is empty", item), item => Assert.Equal("The Guid is invalid and contains 00000000", item), item => Assert.Equal("The card type id has already been taken.", item), item => Assert.Equal("The card type name has already been taken.", item) ); } } }