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.
152 lines
4.2 KiB
152 lines
4.2 KiB
using Model;
|
|
|
|
namespace UTests2;
|
|
|
|
public class UnitTests
|
|
{
|
|
[Fact]
|
|
public async Task Test_AddNewNounours_Success()
|
|
{
|
|
var nounours = new Nounours("chucky.chucky@hell.com");
|
|
|
|
//setup the mocks
|
|
MockNounoursStore nounoursStore = new MockNounoursStore
|
|
{
|
|
Add = n =>
|
|
{
|
|
Assert.Equal(nounours.Email, n?.Email);
|
|
return n;
|
|
}
|
|
};
|
|
|
|
MockEmailService emailService = new MockEmailService
|
|
{
|
|
AskConfirmation = n =>
|
|
{
|
|
Assert.Equal("chucky.chucky@hell.com", n.Email);
|
|
return true;
|
|
}
|
|
};
|
|
|
|
//setup the subject-under-test
|
|
NounoursManager mgr = new NounoursManager(nounoursStore, emailService);
|
|
|
|
//execute the method to test
|
|
bool result = await mgr.AddNewNounours(nounours);
|
|
|
|
//assert the result is correct
|
|
Assert.True(result);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Test_AddNewNounours_Fail_AlreadyExists()
|
|
{
|
|
var nounours = new Nounours("chucky.chucky@hell.com");
|
|
|
|
//setup the mocks
|
|
MockNounoursStore nounoursStore = new MockNounoursStore
|
|
{
|
|
Add = n =>
|
|
{
|
|
Assert.Equal(nounours.Email, n?.Email);
|
|
return null;
|
|
},
|
|
Remove = n =>
|
|
{
|
|
Assert.Equal(nounours.Email, n?.Email);
|
|
return true;
|
|
}
|
|
};
|
|
MockEmailService emailService = new MockEmailService
|
|
{
|
|
AskConfirmation = n =>
|
|
{
|
|
Assert.Equal("chucky.chucky@hell.com", n.Email);
|
|
return true;
|
|
}
|
|
};
|
|
|
|
//setup the subject-under-test
|
|
NounoursManager mgr = new NounoursManager(nounoursStore, emailService);
|
|
|
|
//execute the method to test
|
|
bool result = await mgr.AddNewNounours(nounours);
|
|
|
|
//assert the result is correct
|
|
Assert.False(result);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Test_AddNewNounours_Fail_BadEmail()
|
|
{
|
|
var nounours = new Nounours("chucky.chucky@hell.com");
|
|
|
|
//setup the mocks
|
|
MockNounoursStore nounoursStore = new MockNounoursStore
|
|
{
|
|
Add = n =>
|
|
{
|
|
Assert.Equal(nounours.Email, n?.Email);
|
|
return n;
|
|
},
|
|
Remove = n =>
|
|
{
|
|
Assert.Equal(nounours.Email, n?.Email);
|
|
return true;
|
|
}
|
|
};
|
|
MockEmailService emailService = new MockEmailService
|
|
{
|
|
AskConfirmation = n =>
|
|
{
|
|
Assert.Equal(nounours.Email, n.Email);
|
|
return false;
|
|
}
|
|
};
|
|
|
|
//setup the subject-under-test
|
|
NounoursManager mgr = new NounoursManager(nounoursStore, emailService);
|
|
|
|
//execute the method to test
|
|
bool result = await mgr.AddNewNounours(nounours);
|
|
|
|
//assert the result is correct
|
|
Assert.False(result);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Test_AddNewNounours_Fail_ExceptionWhenRemoving()
|
|
{
|
|
var nounours = new Nounours("chucky.chucky@hell.com");
|
|
|
|
//setup the mocks
|
|
MockNounoursStore nounoursStore = new MockNounoursStore
|
|
{
|
|
Add = n =>
|
|
{
|
|
Assert.Equal(nounours.Email, n?.Email);
|
|
return n;
|
|
},
|
|
Remove = n =>
|
|
{
|
|
Assert.Equal(nounours.Email, n?.Email);
|
|
return false;
|
|
}
|
|
};
|
|
MockEmailService emailService = new MockEmailService
|
|
{
|
|
AskConfirmation = n =>
|
|
{
|
|
Assert.Equal("chucky.chucky@hell.com", n.Email);
|
|
return false;
|
|
}
|
|
};
|
|
|
|
//setup the subject-under-test
|
|
NounoursManager mgr = new NounoursManager(nounoursStore, emailService);
|
|
|
|
|
|
//assert it throws an exception
|
|
_ = await Assert.ThrowsAsync<Exception>(async () => await mgr.AddNewNounours(nounours));
|
|
}
|
|
} |