public async override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { if (context.UserName == null || context.Password == null) { context.Rejected(); return; } var users = new InMemoryUsers(); var user = users.FirstOrDefault(u => u.Name.ToLower().Trim() == context.UserName.ToLower().Trim()); if (user != null) { if (context.Password == user.Name.ToLower()) { var id = new ClaimsIdentity(context.Options.AuthenticationType); id.AddClaim(new Claim("sub", user.Name)); id.AddClaim(new Claim("email", user.Email)); foreach (var role in user.Roles) { id.AddClaim(new Claim("role", role)); } context.Validated(id); } } else { context.Rejected(); } }
public void NestedTransactionThatFailsAbortsWhole() { using (var scope = Database.GetTransaction()) { using (var scope2 = Database.GetTransaction()) { var user1 = new UserDecorated { Name = "Name" + 16, Age = 20 + 16, DateOfBirth = new DateTime(1970, 1, 1).AddYears(16), Savings = 50.00m + (1.01m * 16) }; InMemoryUsers.Add(user1); Database.Insert(user1); var extra1 = new ExtraUserInfoDecorated { UserId = user1.UserId, Email = "email" + 16 + "@email.com", Children = 16 }; InMemoryExtraUserInfos.Add(extra1); Database.Insert(extra1); } var user = new UserDecorated { Name = "Name" + 16, Age = 20 + 16, DateOfBirth = new DateTime(1970, 1, 1).AddYears(16), Savings = 50.00m + (1.01m * 16) }; InMemoryUsers.Add(user); Database.Insert(user); var extra = new ExtraUserInfoDecorated { UserId = user.UserId, Email = "email" + 16 + "@email.com", Children = 16 }; InMemoryExtraUserInfos.Add(extra); Database.Insert(extra); scope.Complete(); } var count = Database.ExecuteScalar <long>("SELECT COUNT(*) FROM Users"); Assert.AreEqual(15, count); }
public void QueryWithInclude() { var users = Database.Query <User>().Include(x => x.House).ToList(); InMemoryUsers.ForEach(x => x.House = InMemoryHouses.SingleOrDefault(y => y.HouseId == x.HouseId)); Assert.AreEqual(15, users.Count); for (int i = 0; i < users.Count; i++) { AssertUserValues(InMemoryUsers[i], users[i]); AssertUserHouseValues(InMemoryUsers[i], users[i]); } }
public void QueryWithIncludeAndNestedOrderBy() { var users = Database.Query <User>().Include(x => x.House).Where(x => x.HouseId != null).OrderBy(x => x.House.Address).ToList(); InMemoryUsers.ForEach(x => x.House = InMemoryHouses.SingleOrDefault(y => y.HouseId == x.HouseId)); var inmemory = InMemoryUsers.Where(x => x.HouseId != null).OrderBy(x => x.House.Address).ToList(); Assert.AreEqual(7, users.Count); for (int i = 0; i < users.Count; i++) { AssertUserValues(inmemory[i], users[i]); AssertUserHouseValues(inmemory[i], users[i]); } }
public void UpdateBatchTest() { var users = InMemoryUsers.Select(x => UpdateBatch.For(x, Database.StartSnapshot(x))).Select(x => { x.Poco.Age = 30; return(x); }); var updated = Database.UpdateBatch(users, new BatchOptions() { BatchSize = 10 }); var result = Database.Query <UserDecorated>().ToList(); Assert.AreEqual(15, result.Count); foreach (var u in result) { Assert.AreEqual(30, u.Age); } Assert.AreEqual(14, updated); }
public void QueryWithIncludeNestedOrderByLimitAndProjection() { var users = Database.Query <User>() .Include(x => x.House) .Where(x => x.House != null) .OrderBy(x => x.House.HouseId) .Limit(5) .ProjectTo(x => new { Address = (x.House != null ? x.House.Address : string.Empty), x.House.HouseId }); var inmemory = InMemoryUsers.Where(x => x.House != null).OrderBy(x => x.House.HouseId).Select(x => new { x.House.Address, x.House.HouseId }).ToList(); Assert.AreEqual(5, users.Count); for (int i = 0; i < users.Count; i++) { Assert.AreEqual(inmemory[i].Address, users[i].Address); Assert.AreEqual(inmemory[i].HouseId, users[i].HouseId); } }
public async Task <ActionResult> Consume([FromBody] ConsumeProductCommand command) { if (command.UserId > 0) { var user = InMemoryUsers.GetUsers().FirstOrDefault(x => x.Id == command.UserId); user.CarbConsumption.Add(new CarbConsumption() { Amount = command.CarbAmount, ConsumedOn = DateTimeOffset.Now }); return(NotModified()); } else { return(NotFound()); } }
public void QueryWithIncludeNestedOrderByLimitAndProjectionToProjectUserWithList() { var users = Database.Query <User>() .Include(x => x.House) .Where(x => x.House != null) .OrderBy(x => x.House.HouseId) .Limit(5) .ProjectTo(x => new ProjectUser() { Array = new object[] { x.Name, x.Age } }); var inmemory = InMemoryUsers.Where(x => x.House != null).OrderBy(x => x.House.HouseId).ToList(); Assert.AreEqual(5, users.Count); for (int i = 0; i < users.Count; i++) { Assert.AreEqual(inmemory[i].Name, users[i].Array[0]); Assert.AreEqual(inmemory[i].Age, users[i].Array[1]); } }
public void QueryWithIncludeNestedOrderByLimitAndProjectionToProjectUser() { var users = Database.Query <User>() .Include(x => x.House) .Where(x => x.House.HouseId > 2) .OrderBy(x => x.House.HouseId) .Limit(5) .ProjectTo(x => new ProjectUser() { UserId = x.UserId, NameWithAge = x.Name + x.Age }); var inmemory = InMemoryUsers.Where(x => x.House != null).OrderBy(x => x.House.HouseId).ToList(); Assert.AreEqual(4, users.Count); for (int i = 0; i < users.Count; i++) { var inMem = inmemory.First(x => x.UserId == users[i].UserId); Assert.AreEqual(inMem.Name + inMem.Age, users[i].NameWithAge); } }
public void QueryWithIncludeNestedOrderByLimitAndProjectionToProjectUser() { var users = Database.Query <User>() .Include(x => x.House) .Where(x => x.HouseId != null) .OrderBy(x => x.House.HouseId) .Limit(5) .ProjectTo(x => new ProjectUser() { NameWithAge = x.Name + x.Age }); InMemoryUsers.ForEach(x => x.House = InMemoryHouses.SingleOrDefault(y => y.HouseId == x.HouseId)); var inmemory = InMemoryUsers.Where(x => x.HouseId != null).OrderBy(x => x.House.HouseId).ToList(); Assert.AreEqual(5, users.Count); for (int i = 0; i < users.Count; i++) { Assert.AreEqual(inmemory[i].Name + inmemory[i].Age, users[i].NameWithAge); } }
public async Task <ActionResult <List <User> > > GetUsers() { List <User> users = InMemoryUsers.GetUsers(); return(Ok(users)); }