Ejemplo n.º 1
0
        public async void UpdateSoftware_Put()
        {
            var query = new SoftwaresController(context);

            var newSoftware = new Software {
                Id = 3, Name = "Row And Go!!!"
            };

            // https://stackoverflow.com/questions/36856073/the-instance-of-entity-type-cannot-be-tracked-because-another-instance-of-this-t/42475617
            var local = context.Software.Local.Where(t => t.Id == 3).FirstOrDefault();

            if (local != null)
            {
                context.Entry(local).State = EntityState.Detached; // only needed for xUnit testing
            }
            var result = await query.PutSoftware(3, newSoftware);  // async

            var added = await query.GetSoftware(3);                // async

            var addedGoodRequest = Assert.IsType <Software>(added.Value);

            Assert.Equal(newSoftware.Name, added.Value.Name);
            Assert.Equal(newSoftware.Id, added.Value.Id);
            Assert.Equal(newSoftware, added.Value);
            Assert.Equal(newSoftware, addedGoodRequest);
            //Assert.Equal(newSoftware, result); // No Content returned so can't check it without changing return value
        }
Ejemplo n.º 2
0
        public async void GetSoftware_Returns_OK()
        {
            var query = new SoftwaresController(context);

            var result = await query.GetSoftware(2);  // async

            Assert.IsType <ActionResult <Software> >(result);
        }
Ejemplo n.º 3
0
        public async void GetSoftware_Get_Id_2()
        {
            var query = new SoftwaresController(context);

            var result = await query.GetSoftware(2);  // async

            Assert.Equal("GymBooker", result.Value.Name);
        }
Ejemplo n.º 4
0
        public async void GetAllSoftware_Check_First_And_Last()
        {
            var query = new SoftwaresController(context);

            var result = await query.GetSoftware();  // async

            Assert.Equal("TrackIT", result.Value.First().Name);
            Assert.Equal("Row&Go!", result.Value.Last().Name);
        }
Ejemplo n.º 5
0
        public async void Check_All_Received()
        {
            var query = new SoftwaresController(context);

            var result = await query.GetSoftware();  // async

            Assert.Equal(3, result.Value.ToList().Count);
            Assert.Equal(3, result.Value.Count());
        }
        public void GetSoftware_ShouldReturnNotFound_WhenInvalidId()
        {
            var controller = new SoftwaresController(new TestLicenseManagerContext());

            var result = controller.GetSoftware(-1, 999);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(NotFoundResult));
        }
        public void GetSoftware_ShouldReturnSoftwareWithSameId()
        {
            var context = GetDemoContext();
            var item    = GetDemoSoftware();

            context.Softwares.Add(item);
            var controller = new SoftwaresController(context);

            var result = controller.GetSoftware(-1, item.SoftwareId) as OkNegotiatedContentResult <Software>;

            Assert.IsNotNull(result);
            Assert.AreEqual(result.Content.SoftwareId, item.SoftwareId);
        }
Ejemplo n.º 8
0
        public async void PostSoftware_Add()
        {
            var query = new SoftwaresController(context);

            var newSoftware = new Software {
                Id = 4, Name = "Bengal Tiger"
            };

            var result = await query.PostSoftware(newSoftware); // async

            var added = await query.GetSoftware(4);             // async

            var resultGoodRequest = Assert.IsType <CreatedAtActionResult>(result.Result);
            var addedGoodRequest  = Assert.IsType <Software>(added.Value);

            Assert.Equal(newSoftware.Name, added.Value.Name);
            Assert.Equal(newSoftware.Id, added.Value.Id);
            Assert.Equal(newSoftware, added.Value);
            Assert.Equal(newSoftware, resultGoodRequest.Value);
            Assert.Equal(newSoftware, addedGoodRequest);
        }