public IHttpActionResult Add(Marble marble) { var db = new MarbleContext(); db.Marbles.Add(marble); db.SaveChanges(); return(Ok(marble)); }
public IHttpActionResult Get() { // this where you talk to your database var ran = new Random(); var marbles = new MarbleContext().MarbleColour.ToList(); var randomIndex = new Random().Next(0, marbles.Count); //index is the position in the list var randomMarble = marbles[randomIndex]; return Ok(randomMarble); }
public async Task Can_CreateAndRetrieve_User(string username) { using (var ctx = new MarbleContext(this.Options)) using (var cmd = new CommandLayer(ctx, this.Principal)) using (var query = new QueryLayer(ctx, this.Principal)) { await cmd.CreateUser(username); var user = await query.GetUserAsync(username); Assert.IsTrue(user is object); Assert.IsTrue(user.Username == username); Assert.IsTrue(user.Principal == this.Principal); Assert.IsTrue(user.MarbleAmount == 0m); } }
public async Task Can_CreateAndRetrieve_Group(string groupName) { using (var ctx = new MarbleContext(this.Options)) using (var cmd = new CommandLayer(ctx, this.Principal)) using (var query = new QueryLayer(ctx, this.Principal)) { var username = "******"; await cmd.CreateUser(username); var user = await query.GetUserAsync(username); await cmd.CreateGroup(groupName, user.Id); var groupId = ctx.Groups.FirstOrDefault().Id; var group = await query.GetGroupAsync(groupId); Assert.IsTrue(group is object); Assert.IsTrue(group.Name == groupName); } }
public async Task Can_CreateAndDelete_Group() { using (var ctx = new MarbleContext(this.Options)) using (var cmd = new CommandLayer(ctx, this.Principal)) using (var query = new QueryLayer(ctx, this.Principal)) { var username = "******"; await cmd.CreateUser(username); var user = await query.GetUserAsync(username); await cmd.CreateGroup("test", user.Id); var groupId = ctx.Groups.FirstOrDefault().Id; await cmd.RemoveGroup(groupId); var actual = await query.GetGroupAsync(groupId); Group expected = null; Assert.AreEqual(actual, expected); } }
public QueryLayer(MarbleContext context, string principal) { this.Context = context; this.Principal = principal; }
public QueryLayer(DbContextOptions <MarbleContext> options, string principal) { this.Context = new MarbleContext(options); this.Principal = principal; }
//get one marble public IHttpActionResult GetOne(int id) { Marble marble = new MarbleContext().Marbles.Find(id); return(Ok(marble)); }
public CommandLayer(MarbleContext context, string principal) { this.Context = context; this.Principal = principal; }