You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.9 KiB

using Model;
namespace UTests;
public class UnitTests
{
[Fact]
public async Task Test_AddNewNounours_Success()
{
//setup the mocks
MockNounoursStore nounoursStore = new MockNounoursStore(canAdd: true, canRemove: true);
MockEmailService emailService = new MockEmailService(sendEmail: true);
//setup the subject-under-test
NounoursManager mgr = new NounoursManager(nounoursStore, emailService);
var nounours = new Nounours("chucky.chucky@hell.com");
//execute the method to test
await mgr.AddNewNounours(nounours);
//assert the interactions went correctly
Assert.Equal(nounours.Email, nounoursStore.AddedNounours?.Email);
Assert.Equal(nounours.Email, emailService.EmailSentTo);
}
[Fact]
public async Task Test_AddNewNounours_Fail_AlreadyExists()
{
//setup the mocks
MockNounoursStore nounoursStore = new MockNounoursStore(canAdd: false, canRemove: true);
MockEmailService emailService = new MockEmailService(sendEmail: true);
//setup the subject-under-test
NounoursManager mgr = new NounoursManager(nounoursStore, emailService);
var nounours = new Nounours("chucky.chucky@hell.com");
//execute the method to test
await mgr.AddNewNounours(nounours);
//assert the interactions went correctly
Assert.Null(nounoursStore.AddedNounours);
Assert.Null(emailService.EmailSentTo);
}
[Fact]
public async Task Test_AddNewNounours_Fail_BadEmail()
{
//setup the mocks
MockNounoursStore nounoursStore = new MockNounoursStore(canAdd: true, canRemove: true);
MockEmailService emailService = new MockEmailService(sendEmail: false);
//setup the subject-under-test
NounoursManager mgr = new NounoursManager(nounoursStore, emailService);
var nounours = new Nounours("chucky.chucky@hell.com");
//execute the method to test
await mgr.AddNewNounours(nounours);
//assert the interactions went correctly
Assert.Null(nounoursStore.AddedNounours);
Assert.Null(emailService.EmailSentTo);
}
[Fact]
public async Task Test_AddNewNounours_Fail_ExceptionWhenRemoving()
{
//setup the mocks
MockNounoursStore nounoursStore = new MockNounoursStore(canAdd: true, canRemove: false);
MockEmailService emailService = new MockEmailService(sendEmail: false);
//setup the subject-under-test
NounoursManager mgr = new NounoursManager(nounoursStore, emailService);
var nounours = new Nounours("chucky.chucky@hell.com");
//assert it throws an exception
_ = await Assert.ThrowsAsync<Exception>(async () => await mgr.AddNewNounours(nounours));
//assert the interactions went correctly
Assert.Equal(nounours.Email, nounoursStore.AddedNounours?.Email);
}
}