Пример #1
0
        public static void ShouldMatch(this Book actual, Book expected, string expectedTitle)
        {
            try
            {
                actual.ShouldNotBeNull();

                actual.Id.ShouldEqual(expected.Id);
                actual.Isbn.ShouldEqual(expected.Isbn);
                actual.Title.ShouldEqual(expectedTitle);

                if (expected.Prices == null)
                {
                    actual.ShouldBeNull();
                    return;
                }

                if (expected.Prices.Count == 0)
                {
                    actual.Prices.ShouldBeEmpty();
                    return;
                }

                actual.Prices.Count.ShouldEqual(expected.Prices.Count);

                foreach (var expectedPrice in expected.Prices)
                {
                    var actualPrice = actual.Prices.FirstOrDefault(x => x.Id == expectedPrice.Id);

                    actualPrice.ShouldNotBeNull();

                    actualPrice.ShouldMatch(expectedPrice);
                }
            }
            catch (SpecificationException e)
            {
                throw new SpecificationException("Expected the actual book matching to expected but it differs by:\n" + e.Message, e);
            }
        }
Пример #2
0
 public static void ShouldMatch(this Book actual, Book expected)
 {
     actual.ShouldMatch(expected, expected.Title);
 }