public void WhenHaveReceivedTooMany_ShouldThrow() { // Arrange var sub = Substitute.For <IFoo>(); var count = GetRandomInt(1, 10); // Act PyLike.Range(0, count + GetRandomInt(1, 10)).ForEach(_ => sub.Bar()); Assert.That(() => Expect(sub).To.Have.Received(count).Bar(), Throws.Exception.InstanceOf <ReceivedCallsException>()); // Assert }
public void WhenHaveReceivedTheCorrectAmount_ShouldNotThrow() { // Arrange var sub = Substitute.For <IFoo>(); var count = GetRandomInt(1, 5); // Act PyLike.Range(0, count).ForEach(_ => sub.Bar()); // Assert Expect(sub).To.Have .Received(count) .Bar(); }
public void Contain_All_MatchedByWithIndex_WhenCollectionHasMismatchesWithMatcher_ShouldThrow() { // Arrange var items = PyLike.Range(10).Select(i => i).ToArray(); // Pre-Assert // Act Assert.That( () => { Expect(items).To.Contain.All().Matched.By((idx, item) => item == idx); }, Throws.Nothing); // Assert }
public void WhenAllMatch_ShouldNotThrow() { // Arrange var search = GetRandomString(4); var collection = PyLike.Range(GetRandomInt(3, 5)).Select(i => search); // Pre-Assert // Act Assert.That(() => { Expect(collection).To.Contain.All().Equal.To(search); }, Throws.Nothing); // Assert }
public void Contain_All_WhenCollectionHasNoMismatches_ShouldNotThrow() { // Arrange var search = GetRandomString(); var collection = PyLike.Range(2, 4).Select(i => search); // Pre-Assert // Act Assert.That( () => { Expect(collection).To.Contain.All().Equal.To(search); }, Throws.Nothing); // Assert }
public void NegatedAlt_WhenAllMatch_ShouldThrow() { // Arrange var search = GetRandomString(4); var collection = PyLike.Range(GetRandomInt(3, 5)).Select(i => search); // Pre-Assert // Act Assert.That(() => { Expect(collection).To.Not.Contain.All().Equal.To(search); }, Throws.Exception.InstanceOf <UnmetExpectationException>()); // Assert }
public void Contain_Any_MatchedByWithIndex_WhenCollectionHasMismatchesWithMatcher_ShouldThrow() { // Arrange var items = PyLike.Range(10).Select(i => i + 1).ToArray(); // Pre-Assert // Act Assert.That( () => { Expect(items).To.Contain.Any().Matched.By((idx, item) => item == idx); }, Throws.Exception .InstanceOf <UnmetExpectationException>() .With.Message.Contains("Expected to find any matching but found none")); // Assert }
public void WhenHaveActualAllMatchingSearch_ShouldNotThrow() { // Arrange var search = GetRandomString(); var actual = PyLike.Range(GetRandomInt(2, 4)).Select(i => search); // Pre-Assert // Act Assert.That(() => { Expect(actual).To.Contain.Any().Equal.To(search); }, Throws.Nothing); // Assert }
public void WhenNotAllMatch_ShouldNotThrow() { // Arrange var search = GetRandomString(4); var collection = PyLike.Range(GetRandomInt(3, 5)) .Select(i => search) .Union(new[] { GetAnother(search) }); // Pre-Assert // Act Assert.That(() => { Expect(collection).To.Contain.All().Equal.To(search); }, Throws.Exception.InstanceOf <UnmetExpectationException>()); // Assert }
public void CopyTo_ShouldCopy_AllUniqueByKey_ToTheGivenIndexOfTheArray() { // Arrange var array = new KeyValuePair <string, string> [10]; const int index = 1; var kvp1 = new KeyValuePair <string, string>("key1", "value1"); var kvp2 = new KeyValuePair <string, string>("key2", "value2"); var kvp3 = new KeyValuePair <string, string>("key3", "value3"); var inner1 = new Dictionary <string, string> { [kvp1.Key] = kvp1.Value, [kvp2.Key] = kvp2.Value }; var inner2 = new Dictionary <string, string>() { ["key1"] = "moocakes", [kvp3.Key] = kvp3.Value }; var sut = Create(inner1, inner2); // Pre-assert // Act sut.CopyTo(array, index); // Assert var defaultVal = default(KeyValuePair <string, string>); Expectations.Expect(array[0]).To.Equal(defaultVal); Expectations.Expect(array.Any(e => e.Equals(kvp1))).To.Be.True(); Expectations.Expect(array.Any(e => e.Equals(kvp2))).To.Be.True(); Expectations.Expect(array.Any(e => e.Equals(kvp3))).To.Be.True(); PyLike.Range(4, 10).ForEach(i => Expectations.Expect(array[i]).To.Equal(defaultVal)); }
public void CopyTo_ShouldCopyKnownKeyValuePairs() { // Arrange var start = RandomValueGen.GetRandomInt(2, 4); var arraySize = RandomValueGen.GetRandomInt(10, 15); var items = RandomValueGen.GetRandomArray <KeyValuePair <string, string> >(2, 4); var target = new KeyValuePair <string, string> [arraySize]; var sut = Create <string, string>(); items.ForEach(sut.Add); // Pre-assert // Act sut.CopyTo(target, start); // Assert var defaultValue = default(KeyValuePair <string, string>); PyLike.Range(start).ForEach(i => Expect(target[i]).To.Equal(defaultValue)); PyLike.Range(start + items.Length, arraySize).ForEach( i => Expect(target[i]).To.Equal(defaultValue)); items.ForEach(i => Expect(target).To.Contain.Exactly(1).Equal.To(i)); }