Esempio n. 1
0
        public async Task Create()
        {
            var sut = new GizmosController(_ctx);

            var maxId = _ctx.Gizmos.Max(r => r.Id);

            var maxRank = _ctx.Gizmos.Max(r => r.Rank);

            var gizmo = new Gizmo {
                Name = "Baz", Rank = maxRank + 1
            };

            var actual = await sut.Create(gizmo);

            Assert.Equal(typeof(CreatedAtRouteResult), actual.GetType());

            var createdResult = actual as CreatedAtRouteResult;

            // endpoint returns gizmo
            Assert.Same(gizmo, createdResult.Value as Gizmo);

            // endpoint assigns next id to gizmo
            Assert.True(gizmo.Id > maxId);
            Assert.Equal(gizmo.Id, _ctx.Gizmos.Max(r => r.Id));

            // endpoint returns correct id in route values
            Assert.Equal(gizmo.Id, createdResult.RouteValues["id"]);
        }
Esempio n. 2
0
        public async Task UpdateNotFound()
        {
            var sut = new GizmosController(_ctx);

            var actual = await sut.Update(0, new Gizmo { Id = 0 });

            Assert.Equal(typeof(NotFoundResult), actual.GetType());
        }
Esempio n. 3
0
        public void ReturnOneNotFound()
        {
            var sut = new GizmosController(_ctx);

            var actual = sut.GetById(0);

            Assert.Equal(typeof(NotFoundResult), actual.GetType());
        }
Esempio n. 4
0
        public async Task UpdateBadRequestIdsNotMatch()
        {
            var sut = new GizmosController(_ctx);

            var actual = await sut.Update(1, new Gizmo { Id = 0 });

            Assert.Equal(typeof(BadRequestResult), actual.GetType());
        }
Esempio n. 5
0
        public async Task UpdateBadRequestNull()
        {
            var sut = new GizmosController(_ctx);

            var actual = await sut.Update(0, null);

            Assert.Equal(typeof(BadRequestResult), actual.GetType());
        }
Esempio n. 6
0
        public async Task GetOverall()
        {
            var sut = new GizmosController(_ctx);

            var actual = await sut.GetAll();

            Assert.Equal(_ctx.Gizmos.Count(), actual.Count());

            GizmosUtils.AssertRanks(actual);
        }
Esempio n. 7
0
        public async Task DeleteNotFound()
        {
            var sut = new GizmosController(_ctx);

            var maxId = _ctx.Gizmos.Max(x => x.Id);

            var actual = await sut.Delete(maxId + 1);

            Assert.Equal(typeof(NotFoundResult), actual.GetType());
        }
Esempio n. 8
0
        public async Task Delete()
        {
            var sut = new GizmosController(_ctx);

            var gizmo = _ctx.Gizmos.Last();

            var actual = await sut.Delete(gizmo.Id);

            Assert.Equal(typeof(NoContentResult), actual.GetType());

            Assert.Null(_ctx.Gizmos.SingleOrDefault(x => x.Id == gizmo.Id));
        }
Esempio n. 9
0
        public void ReturnOne(long id, string name)
        {
            var sut = new GizmosController(_ctx);

            var actual = sut.GetById(id);

            Assert.Equal(typeof(ObjectResult), actual.GetType());

            var objectResult = actual as ObjectResult;

            var gizmo = objectResult.Value as Gizmo;

            Assert.Equal(typeof(Gizmo), gizmo.GetType());

            Assert.Equal(name, gizmo.Name);
        }
Esempio n. 10
0
        public async Task Update()
        {
            var sut = new GizmosController(_ctx);

            var gizmo = _ctx.Gizmos.Last();

            gizmo.Name = "Bar";

            var actual = await sut.Update(gizmo.Id, gizmo);

            Assert.Equal(typeof(NoContentResult), actual.GetType());

            var result1 = _ctx.Gizmos.Single(x => x.Id == gizmo.Id);

            Assert.Equal("Bar", result1.Name);
        }
Esempio n. 11
0
    void GetCoins(bool drawGizmos)
    {
        coinLocations = new Vector2[coinAmount];
        Vector2 pos = transform.position;

        if (drawGizmos)
        {
            GizmosController.DrawPlus(GizmosController.AngleToVector2(coinAngles.x, coinDistance + scale / 2) + pos, 0.5f, Color.blue);
            GizmosController.DrawPlus(GizmosController.AngleToVector2(coinAngles.y, coinDistance + scale / 2) + pos, 0.5f, Color.blue);
        }

        float size = 0.3f;

        for (int i = 0; i < coinLocations.Length; i++)
        {
            coinLocations[i] = GizmosController.AngleToVector2(Mathf.Lerp(coinAngles.x, coinAngles.y, (float)i / (coinLocations.Length - 1)), coinDistance + scale / 2) + pos;
            if (drawGizmos)
            {
                GizmosController.DrawCross(coinLocations[i], size);
            }
            //Debug.Log((float)i/coinLocations.Length);
        }
    }