private static InMemoryDataContext GetTestContext() { var inMemoryDataContext = new InMemoryDataContext(); inMemoryDataContext.Add(new ExampleLeaf() { Id = 1, SecuredRoot = new ExampleRoot() { Id = 1, Name = "Example Root" } }); inMemoryDataContext.Add(new ExampleLeaf() { Id = 2, SecuredRoot = new ExampleRoot() { Id = 2, Name = "Example Root" } }); inMemoryDataContext.Add(new ExampleLeaf() { Id = 3, SecuredRoot = new ExampleRoot() { Id = 4, Name = "A First Record" } }); inMemoryDataContext.Commit(); return(inMemoryDataContext); }
public async Task GetAllSync_WithOneMatchPlayed_ReturnsOneMatch() { // Arrange var matchId = Guid.NewGuid(); var userId = Guid.NewGuid(); var stubMatch = new ApplicationCore.Models.Match.Match { Id = matchId, HomeTeam = new TeamDetails() { UserId = userId, }, AwayTeam = new TeamDetails() { UserId = Guid.NewGuid() } }; var stubMatchList = new List <ApplicationCore.Models.Match.Match>() { stubMatch }; var dbContextStub = new InMemoryDataContext <ApplicationCore.Models.Match.Match>(stubMatchList); // Act var repository = new MatchRepository(dbContextStub); var result = await repository.GetAllAsync(0, 1, userId); //Assert Assert.Equal(stubMatch, result.First()); }
public async Task GetUnclaimedAsync_WhenUserHasAnUnclaimedMatch_ReturnsUnclaimedMatch() { var matchId = Guid.NewGuid(); var userId = Guid.NewGuid(); var stubMatch = new ApplicationCore.Models.Match.Match { Id = matchId, HomeTeam = new TeamDetails() { UserId = userId, HasClaimedRewards = false }, AwayTeam = new TeamDetails() { UserId = Guid.NewGuid() }, KickOff = DateTime.Now.AddMinutes(-100) }; var stubMatchList = new List <ApplicationCore.Models.Match.Match>() { stubMatch }; var dbContextStub = new InMemoryDataContext <ApplicationCore.Models.Match.Match>(stubMatchList); // Act var repository = new MatchRepository(dbContextStub); var result = await repository.GetUnclaimedAsync(userId); //Assert Assert.Equal(stubMatch, result.First()); }
public async Task GetInProgressAsync_WithMatchInProgressAsHomeTeam_ReturnsMatchId() { // Arrange var matchId = Guid.NewGuid(); var userId = Guid.NewGuid(); var stubMatch = new ApplicationCore.Models.Match.Match { Id = matchId, HomeTeam = new TeamDetails() { UserId = userId }, AwayTeam = new TeamDetails() { UserId = Guid.NewGuid() }, KickOff = DateTime.Now.AddMinutes(-10) }; var stubMatchList = new List <ApplicationCore.Models.Match.Match>() { stubMatch }; var dbContextStub = new InMemoryDataContext <ApplicationCore.Models.Match.Match>(stubMatchList); // Act var repository = new MatchRepository(dbContextStub); var result = await repository.GetInProgressAsync(userId); //Assert Assert.Equal(stubMatch.Id, result); }
public async Task GetAllSync_WithMatchNotInvolvingUser_ReturnsEmptyList() { // Arrange var stubMatch = new ApplicationCore.Models.Match.Match { Id = Guid.NewGuid(), HomeTeam = new TeamDetails() { UserId = Guid.NewGuid() }, AwayTeam = new TeamDetails() { UserId = Guid.NewGuid() } }; var stubMatchList = new List <ApplicationCore.Models.Match.Match>() { stubMatch }; var dbContextStub = new InMemoryDataContext <ApplicationCore.Models.Match.Match>(stubMatchList); // Act var repository = new MatchRepository(dbContextStub); var result = await repository.GetAllAsync(0, 1, Guid.NewGuid()); //Assert Assert.False(result.Any()); }
public void DeleteEntityNotFoundTest() { var user1 = new User { Id = Guid.NewGuid(), FirstName = "test1" }; var user2 = new User { Id = Guid.NewGuid(), FirstName = "test2" }; var userList = new List <User> { user1, user2 }; var mockInitialiter = new Mock <IDatabaseInitializer>(); mockInitialiter.Setup(x => x.InitializeTasks()).Returns(new List <Task>()); mockInitialiter.Setup(x => x.InitializeUsers()).Returns(userList); var context = new InMemoryDataContext(mockInitialiter.Object); var user3 = new User { Id = Guid.NewGuid(), FirstName = "user3" }; context.DeleteEntity(user3); Assert.AreEqual(2, context.Users.Count()); }
private static InMemoryDataContext GetTestContext() { var inMemoryDataContext = new InMemoryDataContext(); inMemoryDataContext.Add(new ExampleLeaf() { Id = 1, SecuredRoot = new ExampleRoot() { Id = 1, Name = "Example Root" } }); inMemoryDataContext.Add(new ExampleLeaf() { Id = 2, SecuredRoot = new ExampleRoot() { Id = 2, Name = "Example Root" } }); inMemoryDataContext.Add(new ExampleLeaf() { Id = 3, SecuredRoot = new ExampleRoot() { Id = 4, Name = "A First Record" } }); inMemoryDataContext.Commit(); return inMemoryDataContext; }
public void GetEntityTest() { var testGuid = Guid.NewGuid(); var testName = "test2"; var userList = new List <User> { new User { Id = Guid.NewGuid(), FirstName = "test1" }, new User { Id = testGuid, FirstName = testName } }; var mockInitialiter = new Mock <IDatabaseInitializer>(); mockInitialiter.Setup(x => x.InitializeTasks()).Returns(new List <Task>()); mockInitialiter.Setup(x => x.InitializeUsers()).Returns(userList); var context = new InMemoryDataContext(mockInitialiter.Object); var result = context.GetEntity <User>(testGuid); Assert.AreEqual(testGuid, result.Id); Assert.AreEqual(testName, result.FirstName); }
public void DeleteEntityInvalidTypeTest() { var user1 = new User { Id = Guid.NewGuid(), FirstName = "test1" }; var user2 = new User { Id = Guid.NewGuid(), FirstName = "test2" }; var userList = new List <User> { user1, user2 }; var mockInitialiter = new Mock <IDatabaseInitializer>(); mockInitialiter.Setup(x => x.InitializeTasks()).Returns(new List <Task>()); mockInitialiter.Setup(x => x.InitializeUsers()).Returns(userList); var context = new InMemoryDataContext(mockInitialiter.Object); var user3 = "test"; context.DeleteEntity(user3); }
public void GetEntityInvalidTypeTest() { var testGuid = Guid.NewGuid(); var testName = "test2"; var userList = new List <User> { new User { Id = Guid.NewGuid(), FirstName = "test1" }, new User { Id = testGuid, FirstName = testName } }; var mockInitialiter = new Mock <IDatabaseInitializer>(); mockInitialiter.Setup(x => x.InitializeTasks()).Returns(new List <Task>()); mockInitialiter.Setup(x => x.InitializeUsers()).Returns(userList); var context = new InMemoryDataContext(mockInitialiter.Object); context.GetEntity <string>(testGuid); }
public ActionResult Distribution([FromServices] InMemoryDataContext context, [FromBody] DistributionRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var useCase = new UseCase( _logger, new EmployeeAdapter(context), new CalculationInfluenceAdapter( new AreaCalculator(), new SalaryCalculator(), new AdmissionAtCalculator() ) ); var response = useCase.Execute(new Request( request.AvailableValue )); return(JsonResponse.Success((new DistributionPresenter(response)).Present())); } catch (InsufficientAvailableValueException exception) { return(JsonResponse.Error(exception.Message, 400)); } catch (System.Exception exception) { return(JsonResponse.Error(exception.Message)); } }
public SpeakerTestContext() { var context = new InMemoryDataContext(); var repository = new Repository(context); _speakerService = new SpeakerService(repository); _unitOfWork = context; }
public static EventServiceContext GivenContext() { var inMemoryDataContext = new InMemoryDataContext(); var repository = new Repository(inMemoryDataContext); var eventService = new EventService(repository); var fixture = new Fixture(); return(new EventServiceContext(inMemoryDataContext, repository, eventService, fixture)); }
public BaseDataAccessTester() { _memoryDataContext = new InMemoryDataContext(); AthleteDataAccess.ResolveDataContext = () => _memoryDataContext; UserDataAccess.ResolveDataContext = () => _memoryDataContext; ShoeDataAccess.ResolveDataContext = () => _memoryDataContext; RunDataAccess.ResolveDataContext = () => _memoryDataContext; WorkoutDataAcces.ResolveDataContext = () => _memoryDataContext; }
public async Task InsertExisting_Entity() { var context = new InMemoryDataContext(); var repository = new EntityFrameworkCoreRepository <Customer, InMemoryDataContext>(context); var newEntity = await repository.Insert(new Customer() { Name = _entityDefaultName }); var existing = await repository.Insert(newEntity); }
public async Task Insert_Entity() { var context = new InMemoryDataContext(); var repository = new EntityFrameworkCoreRepository <Customer, InMemoryDataContext>(context); var newEntity = await repository.Insert(new Customer() { Name = _entityDefaultName }); Assert.IsTrue(newEntity.ID > 0); }
public void WhenPassingBlankNameShouldThrowAnException(string name) { var dataContext = new InMemoryDataContext(); var gateway = new InMemoryDataGateway(dataContext); var useCase = new Create(gateway); Assert.Throws <BusinessException>(() => { var result = useCase.Execute(name); }); }
public DownloadServiceTester() { RunTrackEnvironment.MappedFullyQualifiedDownloadDirectory = Environment.CurrentDirectory; RunTrackEnvironment.FullyQualifiedDownloadDirectoryUrl = "Foo"; _inMemoryDataContext = new InMemoryDataContext(); RunDataAccess.ResolveDataContext = () => _inMemoryDataContext; DownloadService.ResolveCsvData = () => new DummyCsvData(); DownloadService.ResolveFileSystem = () => new DummyFileSystem(); }
public void GetAllEntitiesInvalidTypeTest() { var mockInitialiter = new Mock <IDatabaseInitializer>(); mockInitialiter.Setup(x => x.InitializeTasks()).Returns(new List <Task>()); mockInitialiter.Setup(x => x.InitializeUsers()).Returns(new List <User>()); var context = new InMemoryDataContext(mockInitialiter.Object); context.GetAllEntities <string>(); }
public void ShouldNotTryToMapAndThrowNullExceptionWhenAccessingGetterOnlyPropertyThatReferencesANullObject() { var context = new InMemoryDataContext(); context.Add(new Parent()); context.Commit(); var models = new GetParents().Execute(context); models.Should().HaveCount(1); }
public void ShouldAddDriverByName() { //arrange var context = new InMemoryDataContext(); var service = new DriversEducationService(new Repository(context)); //act service.AddDriver("Devlin"); //assert context.AsQueryable<Driver>().Count(x => x.LastName == "Devlin").Should().Be(1); }
private Repository SeededDatabase(IFixture fixture) { var context = new InMemoryDataContext(); context.Add(fixture.Create <Account>()); context.Add(fixture.Create <Account>()); context.Add(fixture.Create <Account>()); context.Commit(); return(new Repository(context)); }
public new static CarServiceContext GivenContext() { AutoMapperInitializor.Init(); var inMemoryDataContext = new InMemoryDataContext(); var repository = new Repository(inMemoryDataContext); var eventService = new EventService(repository); var carService = new CarService(repository); var fixture = new Fixture(); return(new CarServiceContext(fixture, repository, carService, inMemoryDataContext, eventService)); }
public void CanCreateUser() { var context = new InMemoryDataContext(); var userService = new UserService(new Repository(context)); User user = userService.CreateUser( "*****@*****.**"); context.Commit(); user.UserId.Should().NotBe(0); user.Email.Should().Be("*****@*****.**"); }
public async Task GetByName_Entity() { var context = new InMemoryDataContext(); var repository = new EntityFrameworkCoreRepository <Customer, InMemoryDataContext>(context); var newEntity = await repository.Insert(new Customer() { Name = _entityDefaultName }); var existing = await repository.Get(x => x.Name == _entityDefaultName); Assert.IsNotNull(existing); }
public void ShouldPopulateSingleReference() { var context = new InMemoryDataContext(); var child = new Post(); var blog = new Blog("Test"); blog.Posts.Add(child); context.Add(blog); context.Commit(); Assert.IsNotNull(child.Blog); }
public void ShouldPopulateCollectionBasedReference() { var context = new InMemoryDataContext(); var child = new Post(); var blog = new Blog("Test"); child.Blog = blog; context.Add(child); context.Commit(); Assert.AreEqual(1, blog.Posts.Count(x => x == child)); }
public void ShouldAddDriverByName() { //arrange var context = new InMemoryDataContext(); var service = new DriversEducationService(new Repository(context)); //act service.AddDriver("Devlin"); context.Commit(); //assert context.AsQueryable <Driver>().Count(x => x.LastName == "Devlin").Should().Be(1); }
public void AddEntityInvalidTypeTest() { var mockInitialiter = new Mock <IDatabaseInitializer>(); mockInitialiter.Setup(x => x.InitializeTasks()).Returns(new List <Task>()); mockInitialiter.Setup(x => x.InitializeUsers()).Returns(new List <User>()); var context = new InMemoryDataContext(mockInitialiter.Object); var testObj = "test"; context.AddEntity(testObj); }
public void ShouldQueryDriversByName() { //arrange var context = new InMemoryDataContext(); context.Add(new Driver("Devlin", "Liles")); context.Add(new Driver("Tim", "Rayburn")); var service = new DriversEducationService(new Repository(context)); //act Driver driver = service.GetDriver("Liles"); //assert driver.Should().NotBeNull(); }
public void ShouldPopulateBackReferenceCollections() { // Arrange var context = new InMemoryDataContext(); var blog = new Blog(); var post = new Post { Blog = blog }; context.Add(post); context.Commit(); // Act var fetchedBlog = context.AsQueryable<Blog>().First(); // Assert fetchedBlog.Posts.Count().Should().Be(1); }
public async Task GetInProgressAsync_WithNoMatchInProgress_ReturnsNull() { // Arrange var userId = Guid.NewGuid(); var stubMatchList = new List <ApplicationCore.Models.Match.Match>(); var dbContextStub = new InMemoryDataContext <ApplicationCore.Models.Match.Match>(stubMatchList); // Act var repository = new MatchRepository(dbContextStub); var result = await repository.GetInProgressAsync(userId); //Assert Assert.Equal((Guid?)null, result); }
public async Task DeleteByID_Entity() { var context = new InMemoryDataContext(); var repository = new EntityFrameworkCoreRepository <Customer, InMemoryDataContext>(context); var newEntity = await repository.Insert(new Customer() { Name = _entityDefaultName }); await repository.Delete(newEntity.ID); var existing = await repository.Get(newEntity.ID); Assert.IsNull(existing); }
public void SetUp() { model = new CustomerModel() { Customers = A.CreateDummyCustomerModel(), }; context = new InMemoryDataContext(); repo = new Repository(context); customerController = new CustomerController(repo); //mockRepo = Mock.Of<IRepository>(); //Mock.Get(mockRepo) // .Setup(r => r.Context) // .Returns(mockContext); }
public void ShouldGetACollectionWithoutItems() { // Fake data context var dataContext = new InMemoryDataContext() { Items = new List <ToDoItem>() }; var dataGateway = new InMemoryDataGateway(dataContext); // Get items var listUseCase = new List(dataGateway); var items = listUseCase.Execute(); Assert.NotNull(items); Assert.True(items.Count == 0); }
private void InitializeCartWithOneItem(InMemoryDataContext context) { var user = context.Add(User.Create("*****@*****.**")); context.Commit(); var cart = context.Add(Cart.Create(user)); var catalogItem = context.Add(CatalogItem.Create ( sku: "CAFE-314", description: "1 Pound Guatemalan Coffee Beans", unitPrice: 18.80m )); cart.AddItem(catalogItem, 2); context.Commit(); }
public void CanLoadCartWithNoItems() { var context = new InMemoryDataContext(); var repository = new Repository(context); var userService = new UserService(repository); var cartService = GivenCartService(repository); var user = userService.CreateUser("*****@*****.**"); context.Commit(); var cart = cartService.GetCartForUser(user); context.Commit(); cart.CartItems.Count().Should().Be(0); }
public void Setup() { context = new InMemoryDataContext(); repo = new Repository(context); // All tests will fail if the Create does not work repo.Context.Add(new Customer { FirstName = "Kevin", LastName = "Berry", Company = new Company("Improving Enterprises"), Email = "*****@*****.**", Phone = "(555)123-4567" }); repo.Context.Commit(); customerK = repo.Find(new FindCustomerByFirstName("Kevin")).First(); }
public void Setup() { context = new InMemoryDataContext(); repo = new Repository(context); newCustomer = new Customer() { FirstName = "K Bob", LastName = "Jr.", Company = new Company("make things, inc."), Email = "*****@*****.**", Phone = "(555)123-4567" }; repo.Context.Add(newCustomer); repo.Context.Commit(); controller = new HomeController(repo); }
public void ShouldPopulateBackReferenceSingleProperty() { // Arrange var context = new InMemoryDataContext(); var blog = new Blog() { Posts = new List<Post>() { new Post() } }; context.Add(blog); context.Commit(); // Act var fetchedPost = context.AsQueryable<Post>().First(); // Assert fetchedPost.Blog.Should().NotBeNull(); }
public void Init() { var dc = new InMemoryDataContext(); var dcf = new InMemoryDataContextFactory { DataContext = dc }; repository = new UserRepository { DataContext = dc, DataContextFactory = dcf }; }
private BlogCommentRepository GetPersister() { var dc = new InMemoryDataContext(); var dcf = new InMemoryDataContextFactory { DataContext = dc }; return new BlogCommentRepository { DataContext = dc, DataContextFactory = dcf }; }
public IRepository<LeaveItem> CreateRepository() { _dataContext = new InMemoryDataContext<LeaveItem>(); return new InMemoryRepository<LeaveItem>(_dataContext); }
private FamilyRepository GetPersister() { var dc = new InMemoryDataContext(); var dcf = new InMemoryDataContextFactory { DataContext = dc }; return new FamilyRepository { DataContext = dc, DataContextFactory = dcf }; }
public void SetUp() { context = new InMemoryActiveDataContext(); repo = new Repository(context); customerController = new CustomerController(repo); }
private BlogRepository GetPersister() { var dc = new InMemoryDataContext(); var dcf = new InMemoryDataContextFactory { DataContext = dc }; var titleCleaner = MockRepository.GenerateMock<ITitleCleaner>(); return new BlogRepository { DataContext = dc, DataContextFactory = dcf, TitleCleaner = titleCleaner, Cache = new InMemoryCache() }; }
public void Setup() { _context = new InMemoryDataContext(); }
private BlogRepository GetPersister() { var dc = new InMemoryDataContext(); var dcf = new InMemoryDataContextFactory { DataContext = dc }; var titleCleaner = MockRepository.GenerateMock<ITitleCleaner>(); var blogCommentRepository = MockRepository.GenerateMock<IModelLister<IBlogComment, int>>(); return new BlogRepository { DataContext = dc, DataContextFactory = dcf, TitleCleaner = titleCleaner, BlogCommentRepository = blogCommentRepository }; }
private IRepository<LeaveItem> CreateRepository() { var dataContext = new InMemoryDataContext<LeaveItem>(); return new InMemoryRepository<LeaveItem>(dataContext); }
public void Setup() { context = new InMemoryDataContext(); hwyRepo = new Repository(context); customer1 = new Customer() { Id = 1, FirstName = "ajim", LastName = "bob", Company = new Company("aCompany") { Id = 1 }, Email = "*****@*****.**", Phone = "(555)123-1142", BillingAddress = new CustomerBillingAddress() { Street1 = "123 some street", City = "awesome city", State = "TX", ZipCode = "75001" } }; customer2 = new Customer() { Id = 2, FirstName = "bjim", LastName = "bob", Company = new Company("bCompany") { Id = 2 }, Email = "*****@*****.**", Phone = "(555)123-1242", BillingAddress = new CustomerBillingAddress() { Street1 = "223 some street", City = "awesome city", State = "TX", ZipCode = "75001" } }; customer3 = new Customer() { Id = 3, FirstName = "cjim", LastName = "bob", Company = new Company("cCompany") { Id = 3 }, Email = "*****@*****.**", Phone = "(555)123-1342", BillingAddress = new CustomerBillingAddress() { Street1 = "323 some street", City = "awesome city", State = "TX", ZipCode = "75001" } }; hwyRepo.Context.Add(customer1); hwyRepo.Context.Add(customer2); hwyRepo.Context.Add(customer3); hwyRepo.Context.Commit(); }