Esempio n. 1
0
        public void GetAllSubCategories()
        {
            var controller = new SubCategoriesController(context);

            controller.Configuration = new HttpConfiguration();
            WebApiConfig.Register(controller.Configuration);

            var result = controller.GetSubCategories();

            Assert.AreEqual(context.SubCategories.Local.Count, result.Count());
        }
Esempio n. 2
0
        public void GetSingleSubCategory()
        {
            int id = new Random().Next(1, context.SubCategories.Local.Count + 1);

            var controller = new SubCategoriesController(context);

            controller.Configuration = new HttpConfiguration();
            WebApiConfig.Register(controller.Configuration);

            var result = controller.GetSubCategory(id).Queryable.Single();

            Assert.IsNotNull(result);
            Assert.AreEqual(id, result.SubCategoryId);
        }
Esempio n. 3
0
        public void DeleteSubCategory()
        {
            int id = new Random().Next(1, context.SubCategories.Local.Count + 1);

            var controller = new SubCategoriesController(context);

            controller.Configuration = new HttpConfiguration();
            WebApiConfig.Register(controller.Configuration);

            var result = controller.Delete(id) as StatusCodeResult;

            Assert.AreEqual(HttpStatusCode.NoContent, result.StatusCode);
            Assert.IsNull(context.SubCategories.Find(id));
        }
Esempio n. 4
0
        public void PostSubCategory()
        {
            var id = context.SubCategories.Local.Count + 1;

            SubCategory newSubCategory = new SubCategory {
                SubCategoryId = id,
                Name          = "New Category Name",
                CategoryId    = new Random().Next(1, context.Categories.Local.Count + 1)
            };

            var controller = new SubCategoriesController(context);

            controller.Configuration = new HttpConfiguration();
            WebApiConfig.Register(controller.Configuration);

            var result = controller.Post(newSubCategory) as CreatedODataResult <SubCategory>;

            Assert.IsNotNull(result.Entity);
            Assert.AreEqual(id, result.Entity.SubCategoryId);
            Assert.AreNotEqual(context.SubCategories.Local.Count + 1, result.Entity.SubCategoryId);
        }
Esempio n. 5
0
        public void PutSubCategory()
        {
            int id = new Random().Next(1, context.SubCategories.Local.Count + 1);

            //Recolhe dados antes da alteração
            var oldSubCategory = context.SubCategories.Find(id);
            //Guardar em variáveis para os testes
            var oldSubCategoryId = oldSubCategory.SubCategoryId;
            var oldName          = oldSubCategory.Name;
            var oldCategoryId    = oldSubCategory.CategoryId;
            var oldModifiedDate  = oldSubCategory.ModifiedDate;

            //Calcular nova Categoria aleatoria diferente da anterior
            int newCategoryId = new Random().Next(1, context.Categories.Local.Count + 1);

            while (newCategoryId == oldCategoryId)
            {
                newCategoryId = new Random().Next(1, context.Categories.Local.Count + 1);
            }

            var delta = new Delta <SubCategory>(typeof(SubCategory));

            delta.TrySetPropertyValue("SubCategoryId", id);
            delta.TrySetPropertyValue("CategoryId", newCategoryId);
            delta.TrySetPropertyValue("Name", "Modified:" + oldName);

            var controller = new SubCategoriesController(context);

            controller.Configuration = new HttpConfiguration();
            WebApiConfig.Register(controller.Configuration);

            var result = controller.Put(id, delta) as UpdatedODataResult <SubCategory>;

            Assert.IsNotNull(result.Entity);
            Assert.AreEqual(oldSubCategoryId, result.Entity.SubCategoryId);
            Assert.AreNotEqual(oldCategoryId, result.Entity.CategoryId);
            Assert.AreNotEqual(oldName, result.Entity.Name);
            Assert.AreNotEqual(oldModifiedDate, result.Entity.ModifiedDate);
        }
Esempio n. 6
0
        public void SetUp()
        {
            _mediator = Substitute.For <IMediator>();

            _sut = new SubCategoriesController(_mediator);
        }