当前位置: 首页>>代码示例>>C#>>正文


C# FakeRepository类代码示例

本文整理汇总了C#中FakeRepository的典型用法代码示例。如果您正苦于以下问题:C# FakeRepository类的具体用法?C# FakeRepository怎么用?C# FakeRepository使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FakeRepository类属于命名空间,在下文中一共展示了FakeRepository类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InitRepositoryParams

        public void InitRepositoryParams()
        {
            var testData = new List<FakeEntity>();
            for (var i = 1; i <= 150; i++)
            {
                testData.Add(new FakeEntity
                {
                    Id = i,
                    Name = "Entity " + i,
                    Description = null,
                    IsDeleted = i > 100
                });
            }
            IQueryable<FakeEntity> fakeList = testData.AsQueryable();

            IDbSet<FakeEntity> dbSetMock = TestsMockFactory.CreateDbSet(fakeList);

            var dbContextMock = new Mock<FakeDbContext>();
            dbContextMock
                .Setup(x => x.FakeEntities)
                .Returns(dbSetMock);

            repository = new FakeRepository(false, dbContextMock.Object, dbSetMock,
                new InMemoryConfiguration());
        }
开发者ID:MikhailApsalikov,项目名称:Selp,代码行数:25,代码来源:EventsTests.cs

示例2: Setup

		public void Setup()
		{

            subscription = new MailingListSubscription
            {
                Contact = new Contact()
            };

            var repository = new FakeRepository(id => subscription);
		    var repositoryResolver = MockRepository.GenerateStub<IRepositoryResolver>();
		    repositoryResolver.Stub(r => r.GetRepository(typeof (MailingListSubscription))).Return(repository);

			binder = new MailingListSubscriptionBinder(repositoryResolver);


			valueProvider = new FakeValueProvider();
			context = new ModelBindingContext()
			{
                ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(null, typeof(MailingListSubscription)),
				ModelState =  new ModelStateDictionary(),
				ValueProvider = valueProvider
			};

			controllerContext = new ControllerContext
			{
				HttpContext = MockRepository.GenerateStub<HttpContextBase>() 				
			};
			controllerContext.HttpContext.Expect(x => x.Request).Return(MockRepository.GenerateStub<HttpRequestBase>());
			controllerContext.HttpContext.Request.Expect(x => x.Form).Return(new NameValueCollection());
        }
开发者ID:somlea-george,项目名称:sutekishop,代码行数:30,代码来源:MailingListSubscriptionBinderTester.cs

示例3: UpdateEntity_ShouldUpdateEntity

        public void UpdateEntity_ShouldUpdateEntity()
        {
            // arrange
            var obj = new Author { Uid = AuthorUid};
            var storageObj = new Author { Uid = AuthorUid };
            var stub = new FakeRepository(new Dictionary<Type, IEnumerable<IEntity>>
            {
                {typeof (Author), new[] {new Author {Uid = Guid.NewGuid()}, storageObj}}
            });
            var updateCommand = new UpdateCommand<Author>();

            // act
            obj.Name = "foo bar";
            obj.About = "sooo some foor";
            obj.Company = "rook";
            obj.SemanticUid = "foo_bar_rook";
            updateCommand.Entity = obj;
            updateCommand.Execute(stub);

            // assert
            Assert.AreEqual(obj.Name, storageObj.Name);
            Assert.AreEqual(obj.About, storageObj.About);
            Assert.AreEqual(obj.Company, storageObj.Company);
            Assert.AreEqual(obj.SemanticUid, storageObj.SemanticUid);
        }
开发者ID:dev2dev-community,项目名称:d2dsite,代码行数:25,代码来源:UpdateCommandTest.cs

示例4: GetAllStudents_WhenASingleStudentInRepository_ShouldReturnSingleStudent

        public void GetAllStudents_WhenASingleStudentInRepository_ShouldReturnSingleStudent()
        {
            var repository = new FakeRepository<Student>();

            var studentToAdd = new Student()
            {
               FirstName = "TestName"
            };

            repository.entities.Add(studentToAdd);

            var controller = new StudentController(repository);

            var studentModels = controller.GetAll();

            int counter = 0;

            foreach (var a in studentModels)
            {
                counter++;
            }

            Assert.IsTrue(counter == 1);

            foreach (var a in studentModels)
            {
                Assert.AreEqual(studentToAdd.FirstName, a.FirstName);
            }
        }
开发者ID:nnaidenov,项目名称:TelerikAcademy,代码行数:29,代码来源:StudentControllerTests.cs

示例5: InitializeRepository

        public void InitializeRepository()
        {
            var testData = new List<FakeEntity>();
            for (var i = 1; i <= 150; i++)
            {
                testData.Add(new FakeEntity
                {
                    Id = i,
                    Name = "Entity " + i,
                    Description = null,
                    IsDeleted = i > 100
                });
            }

            IDbSet<FakeEntity> dbSet = TestsMockFactory.CreateDbSet(testData);

            var dbContextMock = new Mock<FakeDbContext>();
            dbContextMock
                .Setup(x => x.FakeEntities)
                .Returns(dbSet);

            dbContextMock
                .Setup(s => s.SaveChanges())
                .Throws<DbEntityValidationException>();

            repository = new FakeRepository(true, dbContextMock.Object, dbSet,
                new InMemoryConfiguration());
        }
开发者ID:MikhailApsalikov,项目名称:Selp,代码行数:28,代码来源:DbContextNativeExceptionTests.cs

示例6: GetRequest_GetAllTest_OneCategoryOnly

        public void GetRequest_GetAllTest_OneCategoryOnly()
        {
            FakeRepository<Category> categoryFakeRepository = new FakeRepository<Category>();
            FakeRepository<User> userFakeRepository = new FakeRepository<User>();
            FakeRepository<Thread> threadFakeRepository = new FakeRepository<Thread>();

            string sessionKey = "01234567890123456789012345678901234567890123456789";

            Category category = new Category()
            {
                Name = "Test category"
            };

            categoryFakeRepository.entities.Add(category);

            User user = new User()
            {
                SessionKey = sessionKey
            };

            userFakeRepository.Add(user);

            CategoriesController categoriesController = new CategoriesController(
                categoryFakeRepository, userFakeRepository, threadFakeRepository);

            SetupController(categoriesController);

            var allCategories = categoriesController.GetAll(sessionKey).ToList<string>();

            int expectedCategoryCount = 1;
            Assert.AreEqual(expectedCategoryCount, allCategories.Count);
        }
开发者ID:kbrizov,项目名称:Web-API-Sample-Application,代码行数:32,代码来源:CategoriesControllerTests.cs

示例7: GetAll_WhenValid_ShouldReturnBugsCollection

        public void GetAll_WhenValid_ShouldReturnBugsCollection()
        {
            //arrange
            FakeRepository<Bug> fakeRepo = new FakeRepository<Bug>();

            var bugs = new List<Bug>()
            {
                new Bug()
                {
                    Text = "TEST NEW BUG 1"
                },
                new Bug()
                {
                    Text = "TEST NEW BUG 2"
                },
                new Bug()
                {
                    Text = "TEST NEW BUG 3"
                }
            };            
            
            fakeRepo.Entities = bugs;

            var controller = new BugsController(fakeRepo as IRepository<Bug>);

            //act

            var result = controller.GetAll();

            //assert

            CollectionAssert.AreEquivalent(bugs, result.ToList<Bug>());
        }
开发者ID:VDGone,项目名称:TelerikAcademy-2,代码行数:33,代码来源:BugsControllerTests.cs

示例8: GetReportsTest

        public async Task GetReportsTest()
        {
            //Arrange
            const string tick = "tick";
            var dateTime = new DateTime(2013, 03, 25, 2, 35, 10);
            
            var repositoryFactory = new Mock<IRepositoryFactory>();
            var valueConverter = new Mock<ITableValueConverter>();
            var mapper = new Mock<IReportMapper>();

            var reportEntity = new StandardReportV3Entity() { Tick = tick };
            var domainReport = new DomainReport();
            var reportEntities = new List<StandardReportV3Entity>() { new StandardReportV3Entity(), reportEntity };
            var domainReports = new List<DomainReport>() { domainReport };

            var fakeRepository = new FakeRepository<StandardReportV3Entity>(reportEntities);

            valueConverter.Setup(m => m.DateTimeToTick(dateTime)).Returns(tick);
            repositoryFactory.Setup(m => m.Create<StandardReportV3Entity>(Tables.StandardReportV3)).Returns(fakeRepository);
            mapper.Setup(m => m.ReportEntityToDomain(reportEntity)).Returns(domainReport);

            var reportService = new StandardReportService(repositoryFactory.Object, valueConverter.Object, mapper.Object);

            //Act
            var reports = await reportService.GetReports(dateTime);

            //Assert
            Assert.AreEqual(1, reports.Count);
            Assert.AreEqual(domainReports[0], reports[0]);
        }
开发者ID:GusLab,项目名称:video-portal,代码行数:30,代码来源:StandardReportServiceTest.cs

示例9: Setup

		public void Setup()
		{
            product = new Product
            {
                Reviews =
                    {
                        new Review(),
                        new Review()
                    }
            };

            productRepository = new FakeRepository<Product>(id =>
            {
                product.Id = id;
                return product;
            });

            reviewRepository = MockRepositoryBuilder.CreateReviewRepository();

            commentRepository = MockRepository.GenerateStub<IRepository<IComment>>();

            var comments = new List<IComment>
	        {
                new Comment{ Approved = true },
                new Comment{ Approved = false },
                new Review{ Approved = true },
                new Comment{ Approved = true }
	        }.AsQueryable();
            commentRepository.Stub(r => r.GetAll()).Return(comments);

            controller = new ReviewsController(reviewRepository, productRepository, commentRepository);
		}
开发者ID:somlea-george,项目名称:sutekishop,代码行数:32,代码来源:ReviewsControllerTests.cs

示例10: Add_ValidStudent_CheckIsAdded

        public void Add_ValidStudent_CheckIsAdded()
        {
            var repository = new FakeRepository<Student>();

            string firstName = "Nikolay";
            string lastName = "Kostov";
            var student = MakeSimpleStudent(firstName, lastName);

            repository.Entities.Add(student);

            var controller = new StudentsController(repository);

            var students = controller.Get();

            int count = 0;
            string firstNameInMemory = null;
            foreach (var st in students)
            {
                count++;
                firstNameInMemory = st.FirstName;
            }

            Assert.IsTrue(count == 1);
            Assert.AreEqual(firstName, firstNameInMemory);
        }
开发者ID:quela,项目名称:myprojects,代码行数:25,代码来源:StudentsControllerTest.cs

示例11: Add_ValidStudent_GetStudentById_CheckIsStudentCorrect

        public void Add_ValidStudent_GetStudentById_CheckIsStudentCorrect()
        {
            var repository = new FakeRepository<Student>();

            string firstName = "Nikolay";
            string lastName = "Kostov";
            var student = MakeSimpleStudent(firstName, lastName);

            repository.Entities.Add(student);

            var controller = new StudentsController(repository);

            var allStudents = controller.Get();
            int studentId = 0;
            foreach (var st in allStudents)
            {
                studentId = st.StudentId;
            }

            var studentById = controller.Get(studentId);

            Assert.AreEqual(studentId, studentById.StudentId);
            Assert.AreEqual(firstName, studentById.FirstName);
            Assert.AreEqual(lastName, studentById.LastName);
        }
开发者ID:quela,项目名称:myprojects,代码行数:25,代码来源:StudentsControllerTest.cs

示例12: GetAllStudents_WhenThreeStudentsInRepository_ShouldReturnThreeStudents

        public void GetAllStudents_WhenThreeStudentsInRepository_ShouldReturnThreeStudents()
        {
            var repository = new FakeRepository<Student>();

            var studentToAdd1 = new Student()
            {
                FirstName = "Pesho"
            };
            var studentToAdd2 = new Student()
            {
                FirstName = "Pesho"
            };
            var studentToAdd3 = new Student()
            {
                FirstName = "Pesho"
            };
            repository.entities.Add(studentToAdd1);
            repository.entities.Add(studentToAdd2);
            repository.entities.Add(studentToAdd3);

            var controller = new StudentsController(repository);

            var studentModels = controller.GetAll();
            Assert.IsTrue(studentModels.Count() == 3);
        }
开发者ID:sabrie,项目名称:TelerikAcademy,代码行数:25,代码来源:StudentsControllerTests.cs

示例13: Get_GetAllTest_InvalidSessionKey_NoUserWithSuchSessionKey

        public void Get_GetAllTest_InvalidSessionKey_NoUserWithSuchSessionKey()
        {
            FakeRepository<Post> postFakeRepository = new FakeRepository<Post>();
            FakeRepository<User> userFakeRepository = new FakeRepository<User>();
            FakeRepository<Thread> threadFakeRepository = new FakeRepository<Thread>();
            FakeRepository<Vote> voteFakeRepository = new FakeRepository<Vote>();
            FakeRepository<Comment> commentFakeRepository = new FakeRepository<Comment>();

            User user = new User()
            {
                AuthCode = "0123456789012345678901234567890123456789",
                Username = "TestUsername",
                Nickname = "TestNickname",
                SessionKey = "0SuGqVGqRwitYtijDvHlVfHGotklitbwHdYFkgwIRcIQjRASPQ"
            };

            userFakeRepository.entities.Add(user);

            PostsController threadsController = new PostsController(
                postFakeRepository, userFakeRepository, threadFakeRepository, voteFakeRepository, commentFakeRepository);

            SetupController(threadsController);

            threadsController.GetAll("1InvalidSessionKeyvHlVfHGotklitbwHdYFkgwIRcIQjRAPQ");
        }
开发者ID:kbrizov,项目名称:Web-API-Sample-Application,代码行数:25,代码来源:PostsContollerTests.cs

示例14: ServiceSchool

 public ServiceSchool()
 {
     repository = new FakeRepository();
     foreach (var stud in TestingTools.POCOFactory.GenerateStudents(100))
     {
         repository.Insert(stud);
     }
 }
开发者ID:jmanuelcorral,项目名称:CursoBackend,代码行数:8,代码来源:ServiceSchool.cs

示例15: GetAllStudents_WhenNoStudentsInRepository_ShouldReturnNoStudents

        public void GetAllStudents_WhenNoStudentsInRepository_ShouldReturnNoStudents()
        {
            var repository = new FakeRepository<Student>();
            var controller = new StudentsController(repository);

            var studentModels = controller.GetAll();
            Assert.IsTrue(studentModels.Count() == 0);
        }
开发者ID:sabrie,项目名称:TelerikAcademy,代码行数:8,代码来源:StudentsControllerTests.cs


注:本文中的FakeRepository类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。