Skip to content

Commit

Permalink
Merge pull request #3 from Sfrlrk/Dev
Browse files Browse the repository at this point in the history
Unit test added
  • Loading branch information
Sfrlrk committed Dec 1, 2022
2 parents d6e4906 + 1d9b967 commit ebe0785
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 8 deletions.
2 changes: 2 additions & 0 deletions GuideBook.ReportApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
options.ConnectionString = builder.Configuration.GetSection(nameof(MongoDbConnection) + ":" + MongoDbConnection.ConnectionStringValue).Value;
options.Database = builder.Configuration.GetSection(nameof(MongoDbConnection) + ":" + MongoDbConnection.DatabaseValue).Value;
});
builder.Services.AddScoped<IPersonService, PersonService>();
builder.Services.AddScoped<IPersonRepository, PersonRepository>();
builder.Services.AddScoped<IReportService, ReportService>();
builder.Services.AddScoped<IReportRepository, ReportRepository>();
builder.Services.AddScoped<IContactInfoService, ContactInfoService>();
Expand Down
22 changes: 14 additions & 8 deletions GuideBook.ReportService/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,8 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
var data = Encoding.UTF8.GetString(rawData);
var reportVm = JsonConvert.DeserializeObject<ReportViewModel>(data);
var reportData = await GetReportData(reportVm.Location);
CreateReport(reportVm);
var filePath = ExcelOperations.CreateExcel(reportData);
ChangeType(reportVm.Id, filePath);
SenderService.SendMail(filePath, reportVm.EmailAddress);
channel.BasicAck(e.DeliveryTag, false);
};
}
Expand All @@ -53,14 +48,25 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
}
}

async void CreateReport(ReportViewModel reportVm)
{
var reportData = await GetReportData(reportVm.Location);

var filePath = ExcelOperations.CreateExcel(reportData);

ChangeType(reportVm.Id, filePath);

SenderService.SendMail(filePath, reportVm.EmailAddress);
}

async Task<ExcelReportViewModel> GetReportData(string location)
{
var result = await GetAsync<ServiceResult<ExcelReportViewModel>>("https://localhost:44366/api", $"Contact/GetReportByLocation/{location}");
var result = await GetAsync<ServiceResult<ExcelReportViewModel>>("https://localhost:5048/api", $"Contact/GetReportByLocation/{location}");
return result.Data;
}
async void ChangeType(Guid Id, string filePath)
{
await GetAsync<ServiceResult<bool>>("https://localhost:44302/api", $"/Report/ChangeType/{Id}/{filePath}");
await GetAsync<ServiceResult<bool>>("https://localhost:5100/api", $"/Report/ChangeType/{Id}/{filePath}");
}
async Task<T> GetAsync<T>(string baseUrl, string resource)
{
Expand Down
99 changes: 99 additions & 0 deletions GuideBook.UnitTest/ContactBusinessServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,74 @@ public async Task CreateContactPhone_Test()
Assert.True(testResult);
}

[Fact]
public async Task CreateAsyncContactPhone_Test()
{
var person = new PersonDto()
{
Company = "Create Contact Company",
Name = "Create Contact Name",
Surname = "Create Contact UserName"
};
var addedPerson = await personService.Create(person);
if (!addedPerson.IsSuccess)
{
Assert.True(false, "Person not added");
}

var addInfoUser = await contactInfoService.CreateAsync(new ContactInfoDto()
{
Info = "123456",
ContactType = EnumHelper.EContactType.Phone,
PersonId = addedPerson.Data.Id
});

if (addInfoUser == null)
{
Assert.True(false, "Contact not added");
}

var testResult = addInfoUser.IsDeepEqual(new ContactInfoDto()
{
Id = addInfoUser.Id,
Info = "123456",
ContactType = EnumHelper.EContactType.Phone,
PersonId = addedPerson.Data.Id
});
Assert.True(testResult);
}

[Fact]
public async Task UpdateAsyncContactPhone_Test()
{
var person = new PersonDto()
{
Company = "Create Contact Company",
Name = "Create Contact Name",
Surname = "Create Contact UserName"
};
var addedPerson = await personService.Create(person);
if (!addedPerson.IsSuccess)
{
Assert.True(false, "Person not added");
}

var addInfoUser = await contactInfoService.CreateAsync(new ContactInfoDto()
{
Info = "123456",
ContactType = EnumHelper.EContactType.Phone,
PersonId = addedPerson.Data.Id
});

if (addInfoUser == null)
{
Assert.True(false, "Contact not added");
}

await contactInfoService.UpdateAsync(addInfoUser);
Assert.True(true);
}

[Fact]
public async Task CreateContactLocation_Test()
{
Expand Down Expand Up @@ -149,4 +217,35 @@ public async Task CountContact_Test()
var testResult = await contactInfoService.CountAsync();
Assert.True(testResult > 0, "Contact not found");
}

[Fact]
public async Task GetReportByLocation_Test()
{
var person = new PersonDto()
{
Company = "Create Contact Company",
Name = "Create Contact Name",
Surname = "Create Contact UserName"
};
var addedPerson = await personService.Create(person);
if (!addedPerson.IsSuccess)
{
Assert.True(false, "Person not added");
}

var addInfoUser = await contactInfoService.Create(new ContactInfoDto()
{
Info = "123456",
ContactType = EnumHelper.EContactType.Phone,
PersonId = addedPerson.Data.Id
});

if (!addInfoUser.IsSuccess)
{
Assert.True(false, "Contact not added");
}

var testResult = await contactInfoService.GetReportByLocation("Aydın");
Assert.True(testResult.IsSuccess && testResult.Data != null, "Contact not found");
}
}
19 changes: 19 additions & 0 deletions GuideBook.UnitTest/PersonBusinessServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ public async Task CreatePerson_Test()
Assert.True(testResult);
}

[Fact]
public async Task DeleteAsyncPerson_Test()
{
var person = new PersonDto()
{
Company = "TestCompany",
Name = "TestName",
Surname = "TestSurName"
};
var resultCreatedPerson = await personService.Create(person);
if (!resultCreatedPerson.IsSuccess)
{
Assert.True(false, "Person not created");
}

var testResult = await personService.DeleteAsync(resultCreatedPerson.Data.Id);
Assert.True(testResult != null);
}

[Fact]
public async Task DeletePerson_Test()
{
Expand Down

0 comments on commit ebe0785

Please sign in to comment.