31
loading...
This website collects cookies to deliver better user experience
string testString = "hello";
string expectedOutput = testString.ToUpper();
Assert.Equal(expectedOutput, "HELLO");
string testString = "hello";
string expectedOutput = testString.ToUpper();
expectedOutput.Should().Be("HELLO");
public class ShoppingListGenerator
{
public static List<Item> GenerateItems()
{
return new List<Item>
{
new Item
{
Name = "Apple",
Quantity = 5
},
new Item
{
Name = "Banana",
Quantity = 1
},
new Item
{
Name = "Orange",
Quantity = 3
}
};
}
}
public class ShoppingListGeneratorShould
{
[Fact]
public void MultipleAssertions()
{
var testShoppingList = ShoppingListGenerator.GenerateItems();
testShoppingList.Should().NotBeNullOrEmpty();
testShoppingList.Should().Contain(new Item { Name = "Cheese", Quantity = 2 });
testShoppingList.Should().HaveCount(10);
testShoppingList.Should().OnlyHaveUniqueItems();
}
}
using AssertionScopes;
using FluentAssertions;
using FluentAssertions.Execution;
using System;
using Xunit;
namespace Tests
{
public class ShoppingListGeneratorShould
{
[Fact]
public void MultipleAssertions()
{
var testShoppingList = ShoppingListGenerator.GenerateItems();
using (new AssertionScope())
{
testShoppingList.Should().NotBeNullOrEmpty();
testShoppingList.Should().Contain(new Item { Name = "Cheese", Quantity = 2 });
testShoppingList.Should().HaveCount(10);
testShoppingList.Should().OnlyHaveUniqueItems();
}
}
}
}
Message:
Expected testShoppingList {AssertionScopes.Item
{
Name = "Apple"
Quantity = 5
}, AssertionScopes.Item
{
Name = "Banana"
Quantity = 1
}, AssertionScopes.Item
{
Name = "Orange"
Quantity = 3
}} to contain
AssertionScopes.Item
{
Name = "Cheese"
Quantity = 2
}.
Expected testShoppingList to contain 10 item(s), but found 3.