public void Add_ShouldUseIdentityForType() { //Arrange var entity = new Entity(); //Act _context.Add(entity); _context.Commit(); //Assert entity.Id.Should().NotBe(0); }
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); }
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); }
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(); }
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 CanLoadCartWithOneItem() { var context = new InMemoryDataContext(); InitializeCartWithOneItem(context); var repository = new Repository(context); var userService = new UserService(repository); var cartService = GivenCartService(repository); var user = userService.GetUserByEmail("*****@*****.**"); context.Commit(); var cart = cartService.GetCartForUser(user); context.Commit(); cart.CartItems.Count().Should().Be(1); cart.CartItems.Single().Quantity.Should().Be(2); }
public void ShouldNotTryToMapAndThrowNullExceptionWhenAccessingGetterOnlyPropertyThatReferencesANullObject() { var context = new InMemoryDataContext(); context.Add(new Parent()); context.Commit(); var models = new GetParents().Execute(context); models.Should().HaveCount(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 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 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 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 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 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 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 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 void ShouldQueryDriversByName() { //arrange var context = new InMemoryDataContext(); context.Add(new Driver("Devlin", "Liles")); context.Add(new Driver("Tim", "Rayburn")); context.Commit(); var service = new DriversEducationService(new Repository(context)); //act Driver driver = service.GetDriver("Liles"); //assert driver.Should().NotBeNull(); }
public void ShouldQueryDriversByName() { //arrange var context = new InMemoryDataContext(); context.Add(new Driver("Devlin", "Liles")); context.Add(new Driver("Tim", "Rayburn")); context.Commit(); 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 void ShouldPerformCommitsBetterThan10ms() { //Arrange Stopwatch sw = Stopwatch.StartNew(); for (int i = 0; i < 100; i++) { var blog = new Blog(); _context.Add(blog); blog.Posts.Add(new Post()); _context.Commit(); } sw.Stop(); var averageInsert = sw.ElapsedMilliseconds / 1000; averageInsert.Should().BeLessOrEqualTo(10); Console.WriteLine("Average Time for insert of graph is {0}", averageInsert); }
public void Add_ShouldCreateAFirstIdOfOneEveryTimeForANewInstanceOfIIdentifiableOfShort() { // Arrange var longPerson = new IdentifiablePerson <short>(); _context.Add(longPerson); _context.Commit(); // Act var newLongPerson = new IdentifiablePerson <short>(); _context = new InMemoryDataContext(); _context.Add(newLongPerson); _context.Commit(); // Assert newLongPerson.Id.Should().Be(1); }
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 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 Add_ShouldStoreASite() { //arrange var item = new Site(); //act _context.Add(item); _context.Commit(); //assert Site site = _context.AsQueryable <Site>().First(); site.Should().BeSameAs(item); }