Beispiel #1
0
        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);

        }
Beispiel #3
0
        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);
                    }
        }
Beispiel #4
0
        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);
                    }
        }
Beispiel #5
0
        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);
                    }
        }
Beispiel #6
0
 public QueryLayer(MarbleContext context, string principal)
 {
     this.Context   = context;
     this.Principal = principal;
 }
Beispiel #7
0
 public QueryLayer(DbContextOptions <MarbleContext> options, string principal)
 {
     this.Context   = new MarbleContext(options);
     this.Principal = principal;
 }
Beispiel #8
0
        //get one marble
        public IHttpActionResult GetOne(int id)
        {
            Marble marble = new MarbleContext().Marbles.Find(id);

            return(Ok(marble));
        }
Beispiel #9
0
 public CommandLayer(MarbleContext context, string principal)
 {
     this.Context   = context;
     this.Principal = principal;
 }