コード例 #1
0
        public async void PutAdvertType_Put()
        {
            var query = new AdvertTypesController(context);

            var newAdvertType = new AdvertTypes {
                Id = 3, Type = "Cars", TypeDescription = "Fast"
            };

            // https://stackoverflow.com/questions/36856073/the-instance-of-entity-type-cannot-be-tracked-because-another-instance-of-this-t/42475617
            var local = context.AdvertTypes.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.PutAdvertTypes(3, newAdvertType); // async

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

            Assert.Equal(newAdvertType.Type, added.Value.Type);
            Assert.Equal(newAdvertType.TypeDescription, added.Value.TypeDescription);
            Assert.Equal(newAdvertType.Id, added.Value.Id);
            Assert.Equal(newAdvertType, added.Value);
            Assert.Equal(newAdvertType, result.Value);
        }
コード例 #2
0
        public async void GetAdvertType_Get_Id_2()
        {
            var query = new AdvertTypesController(context);

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

            Assert.Equal("Planes", result.Value.Type);
        }
コード例 #3
0
        public async void GetAllAdvertTypes_Returns_OK()
        {
            var query = new AdvertTypesController(context);

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

            Assert.IsType <ActionResult <IEnumerable <AdvertTypes> > >(result);
        }
コード例 #4
0
        public async void DeleteAdvertTypes_Returns_OK()
        {
            var query = new AdvertTypesController(context);

            var result = await query.DeleteAdvertTypes(3);  // async

            Assert.IsType <ActionResult <AdvertTypes> >(result);
        }
コード例 #5
0
        public async void DeleteAdvertTypes_Delete_Id_3()
        {
            var query = new AdvertTypesController(context);

            var result = await query.DeleteAdvertTypes(3);  // async

            Assert.Equal("Automobiles", result.Value.Type);
        }
コード例 #6
0
        public async void GetAllAdvertTypes_Check_First_And_Last()
        {
            var query = new AdvertTypesController(context);

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

            Assert.Equal("Trains", result.Value.First().Type);
            Assert.Equal("Automobiles", result.Value.Last().Type);
        }
コード例 #7
0
        public async void GetAllAdvertTypes_Check_All_Received()
        {
            var query = new AdvertTypesController(context);

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

            Assert.Equal(3, result.Value.ToList().Count);
            Assert.Equal(3, result.Value.Count());
        }
コード例 #8
0
        public async void PostAdvertTypes_Returns_OK()
        {
            var query = new AdvertTypesController(context);

            var newAdvertType = new AdvertTypes {
                Id = 4, Type = "Bikes", TypeDescription = "Fast"
            };
            var result = await query.PostAdvertTypes(newAdvertType);  // async

            Assert.IsType <ActionResult <AdvertTypes> >(result);
            Assert.IsType <CreatedAtActionResult>(result.Result);
        }
コード例 #9
0
        public async void PostAdvertType_Add()
        {
            var query = new AdvertTypesController(context);

            var newAdvertType = new AdvertTypes {
                Id = 4, Type = "Bikes", TypeDescription = "Fast"
            };

            var result = await query.PostAdvertTypes(newAdvertType); // async

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

            Assert.Equal(newAdvertType.Type, added.Value.Type);
            Assert.Equal(newAdvertType.TypeDescription, added.Value.TypeDescription);
            Assert.Equal(newAdvertType.Id, added.Value.Id);
            Assert.Equal(newAdvertType, added.Value);
            //Assert.Equal(newAdvertType, result.Value); // ??
        }