예제 #1
0
		public async Task GetKraniumAsyncTest()
		{
			var kraniumsMockedList = new List<KraniumEntity>
			{
				new KraniumEntity { Name = "TheKranium", IPAddress = "192.168.0.50" },
				//new Kranium { Name = "TheBackupKranium", IPAddress = "192.168.0.51" },
			}.AsQueryable();

			var mockSet = new Mock<DbSet<KraniumEntity>>();
			mockSet.As<IDbAsyncEnumerable<KraniumEntity>>()
				.Setup(m => m.GetAsyncEnumerator())
				.Returns(new TestDbAsyncEnumerator<KraniumEntity>(kraniumsMockedList.GetEnumerator()));

			mockSet.As<IQueryable<KraniumEntity>>()
				.Setup(m => m.Provider)
				.Returns(new TestDbAsyncQueryProvider<KraniumEntity>(kraniumsMockedList.Provider));

			mockSet.As<IQueryable<KraniumEntity>>().Setup(m => m.Expression).Returns(kraniumsMockedList.Expression);
			mockSet.As<IQueryable<KraniumEntity>>().Setup(m => m.ElementType).Returns(kraniumsMockedList.ElementType);
			mockSet.As<IQueryable<KraniumEntity>>().Setup(m => m.GetEnumerator()).Returns(kraniumsMockedList.GetEnumerator());

			var mockContext = new Mock<IKraniumDbContext>();
			mockContext.Setup(c => c.Kranium).Returns(mockSet.Object);

			var repository = new EfKraniumRepository { Context = mockContext.Object };
			var kranium = await repository.GetKraniumAsync();

			Assert.IsNotNull(kranium);
			Assert.AreEqual("TheKranium", kranium.Name);
			Assert.AreEqual("192.168.0.50", kranium.IPAddress);
		}
예제 #2
0
            public void should_find_the_last_third_element()
            {
                var listToRead = new List<int> {1, 4, 5, 7, 9, 0, -3, 4, 6, 8};
                var target = 3;
                var pointerslow = listToRead.GetEnumerator();
                var pointerfast = listToRead.GetEnumerator();
                for(int i=0; i<target;i++)
                    pointerfast.MoveNext();
                while(pointerfast.MoveNext())
                {
                    pointerslow.MoveNext();
                }
                pointerslow.MoveNext();
                Assert.That(pointerslow.Current.Equals(4));

                var list = new MyLinkedList<int>();
                list.Insert(0);
                list.Insert(1);
                list.Insert(2);
                list.Insert(3);
                list.Insert(4);
                list.Insert(5);
                list.Insert(6);
                Assert.That(list.FindLastNthElement(3).Equals(4));
            }
예제 #3
0
        public void Basics()
        {
            try{
            var parser = new BVE5RouteFileParser();
            var stmt = parser.ParseOneStatement(@"Sound.Load(sounds.txt);");
            var expected1 = new List<TypeDescriber>{
                TypeDescriber.Create(NodeType.Statement, new List<TypeDescriber>{
                    TypeDescriber.Create(NodeType.Invocation, new List<TypeDescriber>{
                        TypeDescriber.Create(NodeType.MemRef, new List<TypeDescriber>{
                            TypeDescriber.Create(NodeType.Identifier, null),
                            TypeDescriber.Create(NodeType.Identifier, null),
                            TypeDescriber.Create(NodeType.Identifier, null)
                        })
                    })
                })
            };
            Helpers.TestStructualEqual(expected1.GetEnumerator(), stmt);
            }
            catch(TypeLoadException e){
                var asms = AppDomain.CurrentDomain.GetAssemblies();
                foreach(var asm in asms)
                    Console.WriteLine(asm.FullName);

                Console.WriteLine(e.Message);
                Console.WriteLine(e.TypeName);
            }
        }
예제 #4
0
        public void MessageReceivedEvent()
        {
            ICollection<RawMessage> expectedOutput = new List<RawMessage>();

            expectedOutput.Add(new RawMessage("THEGAME", "a", "b", "cd ef g"));

            string input = string.Join("\r\n", expectedOutput.Select((message) => message.ToString()).ToArray()) + "\r\n";

            IEnumerator<RawMessage> messageChecker = expectedOutput.GetEnumerator();

            var writer = new IO.Helpers.DummyRawMessageWriter();

            using(var stringReader = new StringReader(input))
            using(var reader = new RawMessageTextReader(stringReader)) {
                using(var client = new Ondit.Client.Client(reader, writer)) {
                    client.RawMessageReceived += delegate(object sender, RawMessageEventArgs e) {
                        bool elementExists = messageChecker.MoveNext();

                        Assert.IsTrue(elementExists);
                        Assert.AreEqual(messageChecker.Current, e.Message);
                    };

                    foreach(var expectedMessage in expectedOutput) {
                        client.HandleMessage();
                    }
                }
            }
        }
예제 #5
0
        public void SetUp()
        {
            var visits = new List<Visit>
            {
                new Visit
                {
                    Id = 1,
                    StartDate = new DateTime(2016, 11, 08, 13, 45, 56),
                    VisitType = new VisitType {Id = 1, Name = "Day Visit"}
                },
                new Visit
                {
                    Id = 2,
                    StartDate = new DateTime(2016, 11, 08, 13, 45, 56),
                    EndDate = new DateTime(2016, 11, 08, 15, 34, 10),
                    VisitType = new VisitType {Id = 1, Name = "Day Visit"}
                }
            }.AsQueryable();

            var visitSetMock = new Mock<IDbSet<Visit>>();
            visitSetMock.Setup(m => m.Provider).Returns(visits.Provider);
            visitSetMock.Setup(m => m.Expression).Returns(visits.Expression);
            visitSetMock.Setup(m => m.ElementType).Returns(visits.ElementType);
            visitSetMock.Setup(m => m.GetEnumerator()).Returns(visits.GetEnumerator());

            sitterContextMock = new Mock<SitterContext>();
            sitterContextMock.Setup(s => s.Visits).Returns(visitSetMock.Object);

            this.visitService = new VisitService(sitterContextMock.Object);
        }
 public void MetaHeader()
 {
     var parser = new BVE5CommonParser("BveTs Station List", BVE5FileKind.StationList);
     var tree = parser.Parse(@"BveTs Station List 1.00
     staA, A, 10:00:00, 10:01:00, 20, 10:00:30, 0, 10, 0.3, soundStaA, soundStaADeperture, 0.05, 5
     ", "<string>", true);
     var expected1 = new List<TypeDescriber>{
         TypeDescriber.Create(NodeType.Tree, new List<TypeDescriber>{
             TypeDescriber.Create(NodeType.Statement, new List<TypeDescriber>{
                 TypeDescriber.Create(NodeType.Invocation, new List<TypeDescriber>{
                     TypeDescriber.Create(NodeType.Identifier, null),
                     TypeDescriber.Create(NodeType.Literal, null),		//staA
                     TypeDescriber.Create(NodeType.Literal, null),		//A
                     TypeDescriber.Create(NodeType.TimeLiteral, null),	//10:30:00
                     TypeDescriber.Create(NodeType.TimeLiteral, null),	//10:30:30
                     TypeDescriber.Create(NodeType.Literal, null),		//20
                     TypeDescriber.Create(NodeType.TimeLiteral, null),	//10:30:00
                     TypeDescriber.Create(NodeType.Literal, null),		//0
                     TypeDescriber.Create(NodeType.Literal, null),		//10
                     TypeDescriber.Create(NodeType.Literal, null),		//0.3
                     TypeDescriber.Create(NodeType.Literal, null),		//soundStaA
                     TypeDescriber.Create(NodeType.Literal, null),		//soundStaADeperture
                     TypeDescriber.Create(NodeType.Literal, null),		//0.05
                     TypeDescriber.Create(NodeType.Literal, null)		//5
                 })
             })
         })
     };
     Assert.IsFalse(parser.HasErrors);
     Helpers.TestStructualEqual(expected1.GetEnumerator(), tree);
 }
예제 #7
0
        public void YieldsFutureDataAtCorrectTime()
        {
            var currentTime = new DateTime(2015, 10, 13);
            var timeProvider = new ManualTimeProvider(currentTime);
            var underlying = new List<Tick>
            {
                new Tick {Time = currentTime.AddSeconds(10)}
            };

            var offsetProvider = new TimeZoneOffsetProvider(DateTimeZone.Utc, new DateTime(2015, 1, 1), new DateTime(2016, 1, 1));
            var frontierAware = new FrontierAwareEnumerator(underlying.GetEnumerator(), timeProvider, offsetProvider);

            for (int i = 0; i < 10; i++)
            {
                timeProvider.AdvanceSeconds(1);
                Assert.IsTrue(frontierAware.MoveNext());
                if (i < 9)
                {
                    Assert.IsNull(frontierAware.Current);
                }
                else
                {
                    Assert.IsNotNull(frontierAware.Current);
                    Assert.AreEqual(underlying[0], frontierAware.Current);
                }
            }
        }
예제 #8
0
        public void T001_GetTag_Must_Fetch_Tags_From_Db_And_Return_Objects_That_Matches_Text_With_Given_Input_Tags()
        {
            // arrange
            var demandedTags = new List<string> { "square", "circle", "cat" };
            var dbTag1 = TagModelFactory.Create(1, "rectangle");
            var dbTag2 = TagModelFactory.Create(2, "circle");
            var dbTag3 = TagModelFactory.Create(3, "flower");
            var dbTag4 = TagModelFactory.Create(4, "square");

            var dbTags = new List<Tag> { dbTag1, dbTag2, dbTag3, dbTag4 }.AsQueryable();

            // arrange-mock
            this.mockTbiContext.Setup(s => s.Tags.Provider).Returns(dbTags.Provider);
            this.mockTbiContext.Setup(s => s.Tags.Expression).Returns(dbTags.Expression);
            this.mockTbiContext.Setup(s => s.Tags.ElementType).Returns(dbTags.ElementType);
            this.mockTbiContext.Setup(s => s.Tags.GetEnumerator()).Returns(dbTags.GetEnumerator());

            // act
            var result = this.sut.GetTags(demandedTags);

            // assert
            Assert.NotNull(result);
            Assert.AreEqual(3, result.Count);
            Assert.True(result.Select(x => x.Id).Contains(4));
            Assert.True(result.Select(x => x.Id).Contains(2));
            Assert.True(result.Select(x => x.Id).Contains(0));

            Assert.True(result.Select(x => x.Text).Contains("square"));
            Assert.True(result.Select(x => x.Text).Contains("circle"));
            Assert.True(result.Select(x => x.Text).Contains("cat"));

            // assert-mock
            this.mockTbiContext.Verify(v => v.Tags, Times.Once);
        }
예제 #9
0
        public void DeberiActualizar()
        {
            var mockSet = new Mock<DbSet<Student>>();
            var mockContext = new Mock<UniversityContext>();
            mockContext.Setup(m => m.Students).Returns(mockSet.Object);
            var existing = new Student { StudentId = 1, Nombre = "Carlos", Paterno = "Estrada", Materno = "Copa", Telefono = 2269587 };
            var data = new Student
            {
                StudentId = 1,
                Nombre = "Carlos",
                Paterno = "Estrada",
                Materno = "Copa",
                Telefono = 2269587,
            };
            var queryable = new List<Student> { data }.AsQueryable();
            mockSet.As<IQueryable<Student>>().Setup(m => m.Provider).Returns(queryable.Provider);
            mockSet.As<IQueryable<Student>>().Setup(m => m.Expression).Returns(queryable.Expression);
            mockSet.As<IQueryable<Student>>().Setup(m => m.ElementType).Returns(queryable.ElementType);
            mockSet.As<IQueryable<Student>>().Setup(m => m.GetEnumerator()).Returns(queryable.GetEnumerator());
            mockContext.Setup(m => m.SaveChanges()).Verifiable();

            var service = new UniversityContextService(mockContext.Object);
            service.UpdateStudent(data);
            var mostrar = service.Show();

            mockContext.Verify();
            Assert.AreEqual(1, mostrar.Count);
            Assert.AreEqual("Carlos", mostrar[0].Nombre);
            Assert.AreEqual(2269587, mostrar[0].Telefono);
        }
        public void GetPeopleOver21YearsOld()
        {
            var peopleOver21YearsOld = new List<Person>
            {
                new Person {Id = "1", Age = 25, Name = "Walter"},
                new Person {Id = "2", Age = 36, Name = "Euan"}
            };

            var expectedQuery = Query.GT("Age", 21);
            var databaseMock = new Mock<IMongoDatabase>();
            var peopleCollectionMock = new Mock<IMongoCollection<Person>>();
            var cursorMock = new Mock<IMongoCursor<Person>>();

            cursorMock.Setup(m => m.GetEnumerator()).Returns(peopleOver21YearsOld.GetEnumerator());

            databaseMock.Setup(m => m.GetCollection<Person>("People"))
                .Returns(peopleCollectionMock.Object);

            peopleCollectionMock.Setup(
                m => m.FindAs<Person>(It.Is<IMongoQuery>(query => query.ToString().Equals(expectedQuery.ToString()))))
                .Returns(cursorMock.Object);

            var applcationService = new ApplicationService(databaseMock.Object);

            Assert.AreEqual(2, applcationService.GetPeopleOver(21).Count());

            databaseMock.VerifyAll();
            peopleCollectionMock.VerifyAll();
            cursorMock.VerifyAll();
        }
예제 #11
0
        public virtual void TestFilteredDocIdSet()
        {
            const int maxdoc = 10;
            DocIdSet innerSet = new DocIdSetAnonymousInnerClassHelper(this, maxdoc);

            DocIdSet filteredSet = new FilteredDocIdSetAnonymousInnerClassHelper(this, innerSet);

            DocIdSetIterator iter = filteredSet.GetIterator();
            List<int?> list = new List<int?>();
            int doc = iter.Advance(3);
            if (doc != DocIdSetIterator.NO_MORE_DOCS)
            {
                list.Add(Convert.ToInt32(doc));
                while ((doc = iter.NextDoc()) != DocIdSetIterator.NO_MORE_DOCS)
                {
                    list.Add(Convert.ToInt32(doc));
                }
            }

            int[] docs = new int[list.Count];
            int c = 0;
            IEnumerator<int?> intIter = list.GetEnumerator();
            while (intIter.MoveNext())
            {
                docs[c++] = (int)intIter.Current;
            }
            int[] answer = new int[] { 4, 6, 8 };
            bool same = Arrays.Equals(answer, docs);
            if (!same)
            {
                Console.WriteLine("answer: " + Arrays.ToString(answer));
                Console.WriteLine("gotten: " + Arrays.ToString(docs));
                Assert.Fail();
            }
        }
 public void Constructor_with_enumerator_argument_should_initialize_instance()
 {
     var items = new List<int> { 1, 2 };
     var subject = new BatchableSource<int>(items.GetEnumerator());
     subject.Batch.Should().BeNull();
     subject.HasMore.Should().BeTrue();
 }
        public void testIndesReturnsAViewForTheRelevantProductID()
        {
            var Products = new List<Product>
            {
                new Product{ID = 1,Title = "FirstProduct",Description = "First Product In Database"}
            }.AsQueryable();

            Mock<IHypermartContext> mockDBContext = new Mock<IHypermartContext>();

            var mockSet = new Mock<DbSet<Product>>();
            mockSet.As<IQueryable<Product>>().Setup(m => m.Provider).Returns(Products.Provider);
            mockSet.As<IQueryable<Product>>().Setup(m => m.Expression).Returns(Products.Expression);
            mockSet.As<IQueryable<Product>>().Setup(m => m.ElementType).Returns(Products.ElementType);
            mockSet.As<IQueryable<Product>>().Setup(m => m.GetEnumerator()).Returns(Products.GetEnumerator());

            mockDBContext.Setup(x => x.Products).Returns(mockSet.Object);

            var xy = mockDBContext.Object.Products.ToList();

            ProductsController SUT = new ProductsController(mockDBContext.Object);
            ActionResult  ViewResults =SUT.Index();
            ViewResult vResult = ViewResults as ViewResult;
            if (vResult != null)
            {
                Assert.AreEqual(string.Empty, vResult.ViewName);
                //Assert.IsInstanceOfType(typeof(Product),vResult.Model.GetType() );
                //Product model = vResult.Model as Product;
                //if (model != null)
                //{
                //    //...
                //}
            }
        }
        public void Can_Add_A_Product_Via_A_Controller()
        {
            var mockEFContext = new Mock<IHypermartContext>();
            var Products = new List<Product>
            {
                new Product{ID = 1,Title = "FirstProduct",Description = "First Product In Database"}
            }.AsQueryable();

            var mockSet = new Mock<DbSet<Product>>();
            mockSet.As<IQueryable<Product>>().Setup(m => m.Provider).Returns(Products.Provider);
            mockSet.As<IQueryable<Product>>().Setup(m => m.Expression).Returns(Products.Expression);
            mockSet.As<IQueryable<Product>>().Setup(m => m.ElementType).Returns(Products.ElementType);
            mockSet.As<IQueryable<Product>>().Setup(m => m.GetEnumerator()).Returns(Products.GetEnumerator());

            mockEFContext.Setup(x => x.Products).Returns(mockSet.Object);

            var prodcontroller = new Open.GI.hypermart.Controllers.ProductsController() { db = mockEFContext.Object };

            var fakeHTTPSession = new TitaniumBunker.PhonySession.FonySession();
            fakeHTTPSession.AddFileUpload(new PhonyUploadFile("Screensjot.jpg", GetResourceAsStrream("TestAPI.img100.jpg"), "JPG"));
            prodcontroller.ControllerContext = fakeHTTPSession.BuildControllerContext(prodcontroller);
            prodcontroller.Url = new UrlHelper(fakeHTTPSession.BuildRequestContext());

            var res = prodcontroller.Create(new Product { ID = 2, Description = "foobar" });
        }
예제 #15
0
 /// <summary>
 /// Setup the children of a folder.
 /// </summary>
 /// <param name="folder">Folder containing the children.</param>
 /// <param name="children">The children of the folder.</param>
 public static void SetupChildren(this Mock<IFolder> folder, params ICmisObject[] children) {
     var list = new Mock<IItemEnumerable<ICmisObject>>();
     var internalList = new List<ICmisObject>(children);
     list.Setup(l => l.TotalNumItems).Returns(children.LongLength);
     list.Setup(l => l.GetEnumerator()).Returns(internalList.GetEnumerator());
     folder.Setup(f => f.GetChildren()).Returns(list.Object);
 }
        public void FetchAllScripts_Test()
        {
            //Arange
            var stubFactory = new Mock<IPrompterDbContextFactory>();
            var stubContext = new Mock<IPrompterDbContext>();
            var scriptDbSet = new Mock<IDbSet<Script>>();

            var script = new Script
            {
                ScriptId = 1,
                Title = "test",
                OptionsId = 1,
                Sections = new List<Section>
                {
                    new Section
                    {
                        Order = 2,
                    },
                    new Section
                    {
                        Order = 1,
                    }
                }
            };

            var fakeScripts = new List<Script>
            {
                script,
                new Script
                {
                    Sections = new List<Section>()
                }
            }.AsQueryable();

            stubFactory.Setup(s => s.Create())
                .Returns(stubContext.Object);

            scriptDbSet.Setup(s => s.Provider)
                .Returns(fakeScripts.Provider);
            scriptDbSet.Setup(s => s.Expression)
                .Returns(fakeScripts.Expression);
            scriptDbSet.Setup(s => s.GetEnumerator())
                .Returns(fakeScripts.GetEnumerator());

            stubContext.Setup(s => s.Scripts)
                .Returns(scriptDbSet.Object);

            var service = new ScriptService(stubFactory.Object);

            //Act
            var actual = service.FetchAllScripts();

            //Assert
            Assert.That(actual.Count, Is.EqualTo(2));
            Assert.That(actual.Contains(script));
            Assert.That(SectionsAreOrdered(actual[0]), Is.True);
            Assert.That(actual[0].Title == "test");
            stubContext.Verify(s => s.Scripts, Times.Once);
        }
예제 #17
0
        public void Execute()
        {
            IEnumerable <ITask> list = new List<ITask> ();
            var iter = list.GetEnumerator ();
            IteratorHandler handler = () => iter;
            var task = new IterativeTask (handler);

            Assert.AreEqual (iter, task.Execute (), "#1");
            Assert.IsNull (task.LinkedIterator, "#2");
        }
예제 #18
0
        public void GetEnumerator_should_return_expected_enumerator()
        {
            var elements = new List<IHtmlElement> {
                new HtmlElement { TagName = "p", InnerHtml = "first" },
                new HtmlElement { TagName = "p", InnerHtml = "second" }
            };
            var collection = new HtmlCollection(elements);

            Assert.That(collection.GetEnumerator(), Is.EqualTo(elements.GetEnumerator()));
        }
예제 #19
0
        public async Task AllAsync_ShouldReturnAllClients_UsingMoq()
        {

            var data = new List<ClientSupplier>
            {
                new ClientSupplier { ClientID = 1 },
                new ClientSupplier { ClientID = 2 },
                new ClientSupplier { ClientID = 3 }
            }.AsQueryable();

            var mockSet = new Mock<DbSet<ClientSupplier>>();
            mockSet.As<IDbAsyncEnumerable<ClientSupplier>>()
                .Setup(m => m.GetAsyncEnumerator())
                .Returns(new FakeDbAsyncEnumerator<ClientSupplier>(data.GetEnumerator()));

            mockSet.As<IQueryable<ClientSupplier>>()
                .Setup(m => m.Provider)
                .Returns(new FakeDbAsyncQueryProvider<ClientSupplier>(data.Provider));

            mockSet.As<IQueryable<ClientSupplier>>().Setup(m => m.Expression).Returns(data.Expression);
            mockSet.As<IQueryable<ClientSupplier>>().Setup(m => m.ElementType).Returns(data.ElementType);
            mockSet.As<IQueryable<ClientSupplier>>().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

            var mockContext = new Mock<IClientContext<ClientContext>>();
            mockContext.Setup(c => c.ClientSuppliers).Returns(mockSet.Object);

            var uow =
               new Mock<IUnitOfWork<ClientContext>>();
            uow.Setup(x => x.Context).Returns(mockContext.Object);

            _repository = new ClientRepository(uow.Object);

            var result = await _repository.AllAsync();

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Count);
            Assert.AreEqual(1, result[0].ClientID);
            Assert.AreEqual(2, result[1].ClientID);
            Assert.AreEqual(3, result[2].ClientID);
        }
        public void ClearBatch_should_clear_batch()
        {
            var items = new List<int> { 1, 2 };
            var subject = new BatchableSource<int>(items.GetEnumerator());
            subject.StartBatch();
            subject.MoveNext();
            var batch = new[] { subject.Current };
            subject.EndBatch(batch);
            subject.Batch.Should().NotBeNull();

            subject.ClearBatch();
            subject.Batch.Should().BeNull();
        }
        public void ShouldUseQueryExecuterToReadInformationFromTheChangelogTable() 
        {
            var readResults = new List<bool> { true, true, true, false };
            var readEnumerator = readResults.GetEnumerator();
            var getResults = new List<ChangeEntry>
                                 {
                                     new ChangeEntry("Alpha", 5)
                                         {
                                             ChangeId = "1",
                                             ScriptName = "05.test.sql",
                                             Status = ScriptStatus.Success,
                                             Output = "Complete"
                                         }, 
                                     new ChangeEntry("Alpha", 9)
                                         {
                                             ChangeId = "2",
                                             ScriptName = "09.test.sql",
                                             Status = ScriptStatus.ProblemResolved,
                                             Output = "Fixed"
                                         }, 
                                     new ChangeEntry("Alpha", 12)
                                         {
                                             ChangeId = "3",
                                             ScriptName = "12.test.sql",
                                             Status = ScriptStatus.Failure,
                                             Output = "Failed"
                                         }, 
                                 };
            var getEnumerator = getResults.GetEnumerator();

            this.expectedResultSet.Setup(rs => rs.Read()).Returns(() =>
            {
                readEnumerator.MoveNext();
                getEnumerator.MoveNext();
                return readEnumerator.Current;
            });
            this.expectedResultSet.Setup(rs => rs["Folder"]).Returns(() => getEnumerator.Current.Folder);
            this.expectedResultSet.Setup(rs => rs["ScriptNumber"]).Returns(() => (short)getEnumerator.Current.ScriptNumber);
            this.expectedResultSet.Setup(rs => rs["ChangeId"]).Returns(() => getEnumerator.Current.ChangeId);
            this.expectedResultSet.Setup(rs => rs["ScriptName"]).Returns(() => getEnumerator.Current.ScriptName);
            this.expectedResultSet.Setup(rs => rs["ScriptStatus"]).Returns(() => (short)getEnumerator.Current.Status);
            this.expectedResultSet.Setup(rs => rs["ScriptOutput"]).Returns(() => getEnumerator.Current.Output);

            var changes = this.schemaVersionManager.GetAppliedChanges().ToList();
        
            Assert.AreEqual(3, changes.Count, "Incorrect number of changes found.");
            for (int i = 0; i < getResults.Count; i++)
            {
                AssertChangeProperties(getResults[i], changes[i]);
            }
        }
예제 #22
0
        public void Should_be_able_to_move_to_next_line()
        {
            lineEnumerator.MoveToNext();
            Assert.AreEqual("a", lineEnumerator.Current.Text);
            lineEnumerator.MoveToNext();
            Assert.AreEqual("b", lineEnumerator.Current.Text);

            var l = new List<string> {"a", "b", "C"};
            var e = l.GetEnumerator();
            var c = e.Current;
            e.MoveNext();
            c = e.Current;
            Assert.AreEqual("a", c);
        }
예제 #23
0
        public void Test_IEnumerable_GetEnumerator()
        {
            // arrange 
            var enumerable = Substitute.For<IEnumerable<string>>();

            List<string> l = new List<string>();
            enumerable.GetEnumerator().Returns<IEnumerator<string>>(l.GetEnumerator());

            // act
            foreach(string s in enumerable)
            {
            }

            enumerable.Received().GetEnumerator();
        }
예제 #24
0
        public void ReturnsTrueWhenNextDataIsAheadOfFrontier()
        {
            var currentTime = new DateTime(2015, 10, 13);
            var timeProvider = new ManualTimeProvider(currentTime);
            var underlying = new List<Tick>
            {
                new Tick {Time = currentTime.AddSeconds(1)}
            };

            var offsetProvider = new TimeZoneOffsetProvider(DateTimeZone.Utc, new DateTime(2015, 1, 1), new DateTime(2016, 1, 1));
            var frontierAware = new FrontierAwareEnumerator(underlying.GetEnumerator(), timeProvider, offsetProvider);

            Assert.IsTrue(frontierAware.MoveNext());
            Assert.IsNull(frontierAware.Current);
        }
        public void TestGetAllProjects_ShouldReturnListOfProjects()
        {
            Solution solution = MockRepository.GenerateStub<Solution>();

              Project legitProject1 = MockRepository.GenerateStub<Project>();
              Project legitProject2 = MockRepository.GenerateStub<Project>();

              List<Project> projectList = new List<Project> {legitProject1, legitProject2};

              solution.Stub(x => x.GetEnumerator()).Return(projectList.GetEnumerator());

              var allSolutionProjectsSearcher = new AllSolutionProjectsSearcher();
              List<Project> returnedProjects = allSolutionProjectsSearcher.GetAllProjects(solution);

              Assert.AreEqual(2, returnedProjects.Count);
        }
예제 #26
0
        public void Delete_WithInvalidWocketId_RemovesRecord()
        {
            // Arrange
            var fakeWocket1 = new Wocket { Id = 1 };
            var fakeWocket2 = new Wocket { Id = 2 };
            var fakeWocket3 = new Wocket { Id = 3 };
            var fakeStore = new List<Wocket> { fakeWocket1, fakeWocket2, fakeWocket3 };
            var mockObjectStore = new Mock<IObjectStore<Wocket>>();
            mockObjectStore.Setup(x => x.GetEnumerator()).Returns(fakeStore.GetEnumerator());

            var repository = new WocketRepository(mockObjectStore.Object);

            // Act
            // Assert
            Assert.Throws<ArgumentException>(() => repository.Delete(99));
        }
예제 #27
0
        public void Method_Scenario_Result()
        {
            var orders = new List<IOrder> { new AmazonOrder(), new EbayOrder() };

            foreach (var order in orders)
            {
               order.Process();
            }

            var enumerator = orders.GetEnumerator();

            while (enumerator.MoveNext())
            {
                if (enumerator.Current != null) enumerator.Current.Process();
            }
        }
            public void should_call_all_element_processor()
            {
                var pageElementProcessorMock = new Mock<IPageElementResourceProcessor>();
                var pageElementProcessors = new List<IPageElementResourceProcessor>()
                {
                    pageElementProcessorMock.Object,
                    pageElementProcessorMock.Object,
                    pageElementProcessorMock.Object
                };

                _pageElementProcessors.Setup(x => x.GetEnumerator()).Returns(pageElementProcessors.GetEnumerator());

                _pageResourceProcessor.ProcessPage(new HtmlDocument(), new Uri("Http://www.test.ru"));

                pageElementProcessorMock.Verify(x => x.ProcessPage(It.IsAny<HtmlDocument>(), It.IsAny<Uri>()),
                    Times.Exactly(3));
            }
        public void FastForwardsOldDataAllowsEquals()
        {
            var start = new DateTime(2015, 10, 10, 13, 0, 0);
            var data = new List<Tick>
            {
                new Tick {Time = start.AddMinutes(-1)},
                new Tick {Time = start.AddSeconds(-1)},
                new Tick {Time = start.AddSeconds(0)},
                new Tick {Time = start.AddSeconds(1)},
            };

            var timeProvider = new ManualTimeProvider(start, TimeZones.Utc);
            var fastForward = new FastForwardEnumerator(data.GetEnumerator(), timeProvider, TimeZones.Utc, TimeSpan.FromSeconds(1));

            Assert.IsTrue(fastForward.MoveNext());
            Assert.AreEqual(start.AddSeconds(-1), fastForward.Current.Time);
        }
예제 #30
0
 public void DeberiaEliminar()
 {
     var mockSet = new Mock<DbSet<Student>>();
     var mockContext = new Mock<UniversityContext>();
     mockContext.Setup(m => m.Students).Returns(mockSet.Object);
     var data = new Student { StudentId = 1, Nombre = "Carlos", Paterno = "Estrada", Materno = "Copa", Telefono = 2269587};
     var queryable = new List<Student> { data }.AsQueryable();
     mockSet.As<IQueryable<Student>>().Setup(m => m.Provider).Returns(queryable.Provider);
     mockSet.As<IQueryable<Student>>().Setup(m => m.Expression).Returns(queryable.Expression);
     mockSet.As<IQueryable<Student>>().Setup(m => m.ElementType).Returns(queryable.ElementType);
     mockSet.As<IQueryable<Student>>().Setup(m => m.GetEnumerator()).Returns(queryable.GetEnumerator());
     mockSet.Setup(m => m.Remove(data)).Verifiable();
     mockContext.Setup(m => m.SaveChanges()).Verifiable();
     var service = new UniversityContextService(mockContext.Object);
     service.DeleteStudent("Carlos");//elimina por nombre
     mockContext.Verify();
 }