Esempio 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
        }
        public void PutSoftware_ShouldFail_WhenDifferentId()
        {
            var controller = new SoftwaresController(new TestLicenseManagerContext());

            var badresult = controller.PutSoftware(999, GetDemoSoftware());

            Assert.IsInstanceOfType(badresult, typeof(BadRequestResult));
        }
        public void PutSoftware_ShouldReturnStatusCode()
        {
            var controller = new SoftwaresController(GetDemoContext());
            var item       = GetDemoSoftware();

            var result = controller.PutSoftware(item.SoftwareId, item) as StatusCodeResult;

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(StatusCodeResult));
            Assert.AreEqual(HttpStatusCode.NoContent, result.StatusCode);
        }
        public void PutSoftware_ShouldFail_WhenInvalidManufacturerId()
        {
            var context = GetDemoContext();
            var item    = GetDemoSoftware();

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

            item.ManufacturerId = 999;

            var result = controller.PutSoftware(item.SoftwareId, item);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(BadRequestErrorMessageResult));
        }
Esempio n. 5
0
        public async void UpdateSoftware_Returns_OK()
        {
            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

            Assert.IsType <NoContentResult>(result);
        }