-
-
Save rklec/15471fecf8b3d04a0593f5c3cad6b6f4 to your computer and use it in GitHub Desktop.
ExampleWithList.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Test] | |
public void Fails_WhenNotCalled() | |
{ | |
var service = Substitute.For<IRegistrationService>(); | |
var expected = new RegistrationModel { Username = "Admin", Password = "123456" }; | |
service.Received(1) | |
.Register(Verify.That<IList<RegistrationModel>>(a => | |
a.Should().BeEquivalentTo(new List<RegistrationModel> { expected }) | |
) | |
); | |
} | |
[Test] | |
public void Fails_WhenWronglyCalled() | |
{ | |
var service = Substitute.For<IRegistrationService>(); | |
var expected = new RegistrationModel { Username = "Admin", Password = "123456" }; | |
service.Register(new List<RegistrationModel> | |
{ | |
new() { Username = "Admin", Password = "but wrong password" } | |
} | |
); | |
service.Received(1) | |
.Register(Verify.That<IList<RegistrationModel>>(a => | |
a.Should().BeEquivalentTo(new List<RegistrationModel> { expected }) | |
) | |
); | |
} | |
[Test] | |
public void Works_WhenNotCalled() | |
{ | |
var service = Substitute.For<IRegistrationService>(); | |
var expected = new RegistrationModel { Username = "Admin", Password = "123456" }; | |
service.Register(new List<RegistrationModel> { expected }); | |
service.Received(1) | |
.Register(Verify.That<IList<RegistrationModel>>(a => | |
a.Should().BeEquivalentTo(new List<RegistrationModel> { expected }) | |
) | |
); | |
} | |
public class RegistrationModel | |
{ | |
public string Username { get; set; } | |
public string Password { get; set; } | |
} | |
public interface IRegistrationService | |
{ | |
void Register(IList<RegistrationModel> that); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment