Esempio n. 1
0
        public IHttpActionResult Add(Marble marble)
        {
            var db = new MarbleContext();

            db.Marbles.Add(marble);
            db.SaveChanges();
            return(Ok(marble));
        }
Esempio n. 2
0
        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);

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

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