Example #1
0
 public void OriginalThing_DoesThing()
 {
     var strings = new List<string>();
     new OriginalThing().DoesThing(strings);
     strings.Should().NotBeEmpty();
     strings.Should().HaveCount(1);
     strings.ElementAt(0).Should().Contain("Original");
 }
Example #2
0
 public void ProvidedOriginalThing_DoesThing()
 {
     var strings = new List<string>();
     var thingServer = new Mock<IThingFactory>();
     thingServer.Setup(ts => ts.GetThing()).Returns(new OriginalThing());
     thingServer.Object.GetThing().DoesThing(strings);
     strings.Should().NotBeEmpty();
     strings.Should().HaveCount(1);
     strings.ElementAt(0).Should().Contain("Original");
 }
		public void given_guarantor_with_no_first_name_when_validating_should_return_result_with_resource_value()
		{
			var guarantor = new GuarantorWithGlobalResources { LastName = "Meinershagen" };

			var results = new List<ValidationResult>();
			guarantor.TryValidate(results);

			results.Should().Contain(r => r.ErrorMessage == Resources.GuarantorFirstNameRequired);
			results.Should().NotContain(r => r.ErrorMessage == Resources.ResourceManager.GetString("GuarantorLastNameRequired"));
		}
Example #4
0
        public void TestAddToCollection()
        {
            var collection = new List<string> {"a", "b", "c"};
            var command = new AddToCollection<string>(collection, "d");

            command.Execute();
            collection.Should().Contain("d");

            command.Undo();
            collection.Should().NotContain("d");
        }
        public void given_valid_person_when_trying_to_validate_should_return_true_and_empty_results()
        {
			var results = new List<ValidationResult>();
            var complexPerson = new PersonWithBuiltInValidation{FirstName = "Todd", LastName = "Meinershagen", EmailAddress = "*****@*****.**"};
            complexPerson.TryValidate(results).Should().BeTrue();
			results.Should().BeEmpty();

            var simplePerson = new PersonWithCustomValidation { FirstName = "Todd", LastName = "Meinershagen", EmailAddress = "*****@*****.**" };
            simplePerson.TryValidate(results).Should().BeTrue();
			results.Should().BeEmpty();
        }
Example #6
0
        public void TestExecute()
        {
            var list = new List<string> {"a", "b", "c"};
            var command = new ReplaceInList<string>(list, "b", "x");

            command.Execute();
            list.Should().Equal("a", "x", "c");

            command.Undo();
            list.Should().Equal("a", "b", "c");
        }
        public void TestAddIfNew()
        {
            var list = new List<string> {"a", "b", "c"};

            list.AddIfNew("b").Should().BeFalse();
            list.Should().Equal("a", "b", "c");

            list.AddIfNew("d").Should().BeTrue();
            list.Should().Equal("a", "b", "c", "d");

            list.Invoking(x => x.RemoveLast(-1)).ShouldThrow<ArgumentOutOfRangeException>();
        }
Example #8
0
        public void ProvidedOriginalThing_DoesThing()
        {
            var strings = new List<string>();
            var factory = new OriginalThingFactory();
            var originalThing = factory.GetThing();

            originalThing.Should().BeOfType<OriginalThing>();

            originalThing.DoesThing(strings);
            strings.Should().NotBeEmpty();
            strings.Should().HaveCount(1);
            strings.ElementAt(0).Should().Contain("Original");
        }
Example #9
0
        public void ProvidedFakeThing_DoesThing()
        {
            var strings = new List<string>();
            var factory = new FakeThingFactory();
            var fakeThing = factory.GetThing();

            fakeThing.Should().BeOfType<FakeThing>();

            fakeThing.DoesThing(strings);

            strings.Should().NotBeEmpty();
            strings.Should().HaveCount(1);
            strings.ElementAt(0).Should().Contain("Fake");
        }
        public async Task Activity_is_notified_when_a_command_is_scheduled()
        {
            // arrange
            var order = CommandSchedulingTests_EventSourced.CreateOrder();

            var activity = new List<ICommandSchedulerActivity>();

            using (Configuration.Current
                                .Container
                                .Resolve<SqlCommandScheduler>()
                                .Activity
                                .Subscribe(activity.Add))
            {
                // act
                order.Apply(new ShipOn(Clock.Now().Add(TimeSpan.FromDays(2))));
                await orderRepository.Save(order);

                //assert 
                activity.Should()
                        .ContainSingle(a => a.ScheduledCommand
                                             .IfTypeIs<IScheduledCommand<Order>>()
                                             .Then(c => c.TargetId == order.Id.ToString())
                                             .ElseDefault() &&
                                            a is CommandScheduled);
            }
        }
Example #11
0
        public void given_trip_with_date_not_after_today_when_checking_is_valid_should_be_false()
        {
	        var results = new List<ValidationResult>();
            var trip = new Trip { Date = 23.November(1972) };
            trip.TryValidate(results).Should().BeFalse();
	        results.Should().NotBeEmpty();
        }
 public void ArgumentStaticPassedByReference()
 {
     var assignTo = new List<string>();
     var expectedList = new[] { "newItemForStatic" };
     typeof(TestClass).Invoke("ProtectedStaticMethod", NoTypeArguments, assignTo);
     assignTo.Should().BeEquivalentTo(expectedList).And.HaveSameCount(expectedList);
 }
 public void ArgumentInstancePassedByReference()
 {
     var assignTo = new List<string>();
     var expectedList = new[] { "newItem" };
     new TestClass().Call("ProtectedMethod", null, assignTo);
     assignTo.Should().BeEquivalentTo(expectedList).And.HaveSameCount(expectedList);
 }
 public void TestMatch1()
 {
     var filter = new SubstringFilter("Foobar", true);
     var matches = new List<LogLineMatch>();
     new Action(() => filter.Match(new LogLine(0, 0, null, LevelFlags.All), matches)).ShouldNotThrow();
     matches.Should().BeEmpty();
 }
        public void when_attempting_to_restore_an_externally_tracked_list()
        {
            var mementor = new Mementor(isEnabled: true);

            var collection = new List<string>();
            var item = "hey!";
            mementor.ElementAdd(collection, item);//this is an extension method? Oh I see, he didnt want to put custom-list logic on Mementor. Nice.
            //it also doesnt actually add the element to the list:
            collection.Add(item);
            collection.Should().HaveCount(1);

            mementor.Undo();
            //hmm, so it expects the caller to do the Add but it will handle the remove?

            collection.Should().BeEmpty();
        }
Example #16
0
        public void JsonReader_should_support_reading_multiple_documents(
            [Range(0, 3)]
            int numberOfDocuments)
        {
            var document = new BsonDocument("x", 1);
            var json = document.ToJson();
            var input = Enumerable.Repeat(json, numberOfDocuments).Aggregate("", (a, j) => a + j);
            var expectedResult = Enumerable.Repeat(document, numberOfDocuments);

            using (var jsonReader = new JsonReader(input))
            {
                var result = new List<BsonDocument>();

                while (!jsonReader.IsAtEndOfFile())
                {
                    jsonReader.ReadStartDocument();
                    var name = jsonReader.ReadName();
                    var value = jsonReader.ReadInt32();
                    jsonReader.ReadEndDocument();

                    var resultDocument = new BsonDocument(name, value);
                    result.Add(resultDocument);
                }

                result.Should().Equal(expectedResult);
            }
        }
        public void Items_From_Source_Are_Added() {
            var target = new List<int>();
            var source = new List<int>() {1, 2, 3, 4, 5};

            target.Mirror(source);
            target.Should().Equal(source);
        }
        public void BsonBinaryReader_should_support_reading_multiple_documents(
            [Range(0, 3)]
            int numberOfDocuments)
        {
            var document = new BsonDocument("x", 1);
            var bson = document.ToBson();
            var input = Enumerable.Repeat(bson, numberOfDocuments).Aggregate(Enumerable.Empty<byte>(), (a, b) => a.Concat(b)).ToArray();
            var expectedResult = Enumerable.Repeat(document, numberOfDocuments);

            using (var stream = new MemoryStream(input))
            using (var binaryReader = new BsonBinaryReader(stream))
            {
                var result = new List<BsonDocument>();

                while (!binaryReader.IsAtEndOfFile())
                {
                    binaryReader.ReadStartDocument();
                    var name = binaryReader.ReadName();
                    var value = binaryReader.ReadInt32();
                    binaryReader.ReadEndDocument();

                    var resultDocument = new BsonDocument(name, value);
                    result.Add(resultDocument);
                }

                result.Should().Equal(expectedResult);
            }
        }
        public void TestRemoveLast()
        {
            var list = new List<string> {"a", "b", "c"};
            list.RemoveLast(2);
            list.Should().Equal("a");

            list.Invoking(x => x.RemoveLast(-1)).ShouldThrow<ArgumentOutOfRangeException>();
        }
Example #20
0
 public void Random_42_liefert_immer_folgende_Werte() {
     var random = new Random(42);
     var result = new List<int>();
     for (int i = 0; i < 10; i++) {
         result.Add(random.Next(1, 6 + 1));
     }
     result.Should().Equal(5, 1, 1, 4, 2, 2, 5, 4, 2, 5);
 }
        public void CanGetFromListIndexed()
        {
            var obj = new List<int> { 1, 2, 3, 42, 5 };
            var prop = typeof(List<int>).GetProperty("Item").ToSettable();

            prop.Get(obj, 3).Should().Be(42);
            prop.Set(obj, 3, 43);
            obj.Should().Have.SameSequenceAs(1, 2, 3, 43, 5);
        }
        public void Filtered_Items_Are_Not_Added_Initially()
        {
            var target = new List<int>();
            var source = new ObservableCollection<int> { 1, 2, 3, 4, 5 };

            target.Mirror(source, x => x % 2 == 0);

            target.Should().Equal(new[] { 2, 4 });
        }
        public void Clearing_Source_Collection_Clears_Target_After_Mirror_Call() {
            var target = new List<int>();
            var source = new ObservableCollection<int> { 1, 2, 3, 4, 5 };

            target.Mirror(source);
            source.Clear();

            target.Should().Equal(source);
        }
        public void AllPropertiesShouldGetColumns()
        {
            var columnNames = new List<string>();
            for (var colIndex = 0; colIndex < _result.Columns.Count; colIndex++)
            {
                columnNames.Add(_result.Columns[colIndex].ColumnName);
            }

            columnNames.Should().Contain(new[]{ "Id", "Name", "OtherValue" });
        }
        public void Items_Added_To_Source_After_Mirror_Call_Are_Added_To_Target() {
            var target = new List<int>();
            var source = new ObservableCollection<int> { 1, 2, 3, 4, 5 };

            target.Mirror(source);
            source.Add(6);
            source.Add(7);

            target.Should().Equal(source);
        }
        public void GetRandomItemTest()
        {
            var list = new List<String> { "a", "b", "c", "d" };
            var actual = list.GetRandomItem();

            actual.Should()
                  .NotBeNull();
            list.Should()
                .Contain( actual );
        }
Example #27
0
        public void TestCallback()
        {
            var target = new[] {"element1", "element2", "element2"};
            var calledFor = new List<string>();

            var task = new ForEachTask<string>("Test task", target, calledFor.Add);
            task.Run();

            calledFor.Should().Equal(target);
        }
 public void Then_no_results_should_be_returned()
 {
     var list = new List<HtmlDoc>();
     var httpClient = new HttpClient { UserAgentName = "badbot" };
     var scraper = new Scraper(httpClient, new ScrapedUrisDictionary());
     scraper.Subscribe(new ConsoleWriterObserver());
     scraper.Subscribe(list.Add);
     scraper.Scrape(new Uri("http://localhost:12345")).Wait();
     list.Should().BeEmpty();
 }
        public void ForEach()
        {
            var items = new [] {1, 2, 3};
            
            var results = new List<int>();

            items.ForEach(results.Add);

            results
                .Should("elements should be equal").Have.SameSequenceAs(items);
        }
Example #30
0
 private void AssertServers(List<ServerDescription> actual, List<ServerDescription> expected)
 {
     if (expected.Count == 0)
     {
         actual.Count.Should().Be(0);
     }
     else
     {
         actual.Should().OnlyContain(x => expected.Any(y => EndPointHelper.Equals(x.EndPoint, y.EndPoint)));
     }
 }