public void OneToMany() { var sw = new Stopwatch(); sw.Start(); using (var context = new TestContext2("Server=.;Initial Catalog=TestDb;Integrated security=True;")) { Console.WriteLine("Init: " + sw.Elapsed); sw.Restart(); var country = context.Countries.First(c => c.Name == "Hungary"); Console.WriteLine("Select: " + sw.Elapsed); } }
public void SelectByJoinedTableValue() { var sw = new Stopwatch(); sw.Start(); using (var context = new TestContext2("Server=.;Initial Catalog=TestDb;Integrated security=True;")) { Console.WriteLine("Init: " + sw.Elapsed); sw.Restart(); var stored = context.Address.Where(a => a.CurrentCity.Country.Name == "Hungary" || a.Hometown.Country.Name == "Hungary").Select(a => a.Street).First(); Console.WriteLine("Select: " + sw.Elapsed); } }
public void ForeignKeysWriteAndReadBack() { var sw = new Stopwatch(); sw.Start(); using (var context = new TestContext2("Server=.;Initial Catalog=TestDb;Integrated security=True;")) { Console.WriteLine("Init: " + sw.Elapsed); sw.Restart(); var hungary = new Country { Name = "Hungary" }; var address = new Address { Street = "Futo utca", CurrentCity = new City { Name = "Budapest", Country = hungary }, Hometown = new City { Name = "Mosonmagyarovar", Country = hungary } }; context.Address.Add(address); context.SaveChanges(); Console.WriteLine("Insert: " + sw.Elapsed); sw.Restart(); var stored = context.Address.First(a => a.Street == "Futo utca"); Console.WriteLine("Select: " + sw.Elapsed); Assert.AreNotEqual(stored.Id, 0); Assert.AreEqual(address.Street, stored.Street); Assert.AreNotEqual(stored.CurrentCity.Id, 0); Assert.AreEqual(address.CurrentCity.Name, stored.CurrentCity.Name); Assert.AreNotEqual(stored.Hometown.Id, 0); Assert.AreEqual(address.Hometown.Name, stored.Hometown.Name); } }
public void Initialize() { var documentStore = GetSession(out IDocumentSession documentSession); _contextId = Guid.NewGuid(); var testContext2 = new TestContext2 { ContextId = _contextId, AssertContent = "My-Init-Test-Content" }; testContext2.Claims.Add(new UserClaim { Type = "CustomType", Value = "CustomValue" }); var entity = new User { Username = "******", Id = null, Contexts = new List <Context> { new Context { Id = testContext2.ContextId.ToString(), Claims = testContext2.Claims, Content = JsonConvert.SerializeObject(testContext2), Type = testContext2.GetType().FullName } } }; documentSession.Store(entity); documentSession.SaveChanges(); _testUserId = entity.Id; _documentSessionFactory = new DocumentSessionFactory(documentStore, new NullLogger(), false); _userContextService = new UserContextService(new DocumentStore(_documentSessionFactory, new Raven.Client.Documents.DocumentStore())); }
public void RemoveCascade_OptIn() { using (var context = TestContext2.CreateInstance()) { Assert.NotEmpty(context.User); context.RemoveRangeCascade(context.Order.ToList()); context.SaveChanges(); Assert.NotEmpty(context.User); Assert.Empty(context.Order); Assert.Empty(context.OrderItem); } using (var context = TestContext2.CreateInstance()) { Assert.NotEmpty(context.Product); Assert.NotEmpty(context.Order); Assert.NotEmpty(context.OrderItem); Assert.NotEmpty(context.ProductCategory); context.RemoveRangeCascade(context.Product.ToList()); context.SaveChanges(); Assert.Empty(context.Product); Assert.NotEmpty(context.Order); Assert.Empty(context.OrderItem); Assert.NotEmpty(context.ProductCategory); } using (var context = TestContext2.CreateInstance()) { var user = context.User.First(); int productTotalCount = context.Product.Count(); context.RemoveCascade(user); context.SaveChanges(); Assert.Empty(context.User.Where(x => x.Account == user.Account)); Assert.Empty(context.Order.Where(x => x.UserAccount == user.Account)); Assert.Equal(productTotalCount, context.Product.Count()); } using (var context = TestContext2.CreateInstance()) { var category = context.ProductCategory.First(); context.RemoveCascade(category); context.SaveChanges(); Assert.Empty(context.ProductCategory.Where(x => x.ParentId == category.Id)); Assert.Empty(context.Product.Where(x => x.CategoryId == category.Id)); } using (var context = TestContext2.CreateInstance()) { var category = context.ProductCategory.First(x => x.ParentId.HasValue); var categoryParentId = category.ParentId; context.RemoveCascade(category); context.SaveChanges(); Assert.Empty(context.ProductCategory.Where(x => x.ParentId == category.Id)); Assert.Empty(context.Product.Where(x => x.CategoryId == category.Id)); Assert.NotEmpty(context.ProductCategory.Where(x => x.Id == categoryParentId)); } }