Skip to content

Instantly share code, notes, and snippets.

@rklec
Created August 9, 2023 15:07
Show Gist options
  • Save rklec/15471fecf8b3d04a0593f5c3cad6b6f4 to your computer and use it in GitHub Desktop.
Save rklec/15471fecf8b3d04a0593f5c3cad6b6f4 to your computer and use it in GitHub Desktop.
ExampleWithList.cs
[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