Beispiel #1
0
        public void Generic_Create_Service()
        {
            var fakeContext = new FakeContext("Generic_Create_Service");

            fakeContext.FillWithAll();

            using (var context = new MainContext(fakeContext.FakeOptions, fakeContext.FakeConfiguration().Object))
            {
                var repository = new GenericRepository <Product>(context);
                var service    = new GenericService <Product>(repository);

                var product = new Product("1000", "Product 1", 10M, 15, new DateTime(2019, 03, 10),
                                          new DateTime(2020, 7, 14));

                var response = service.Create(product);

                Assert.Equal(6, service.GetAll().Count());
                Assert.Equal("{ Message = Produto cadastrado com sucesso. }", response.ToString());
                Assert.Equal("1000", service.GetById(6).Sku);
                Assert.Equal("Product 1", service.GetById(6).Name);
                Assert.Equal(10M, service.GetById(6).Price);
                Assert.Equal(15, service.GetById(6).Quantity);
                Assert.Equal(2019, service.GetById(6).CreatedAt.Year);
            }
        }
Beispiel #2
0
        // todo: tests
        public ActionResult Edit(int productId, int versionId)
        {
            var version = service.GetById(versionId);

            if (version == null || version.Product.Id != productId)
            {
                return(new HttpNotFoundResult());
            }
            else
            {
                var vm = converter.EntityToViewmodel(version);
                return(View(vm));
            }
        }
Beispiel #3
0
        // todo: tests
        public ActionResult Edit(int productId, int featureId)
        {
            var feature = service.GetById(featureId);

            if (feature == null || feature.Product.Id != productId)
            {
                return(new HttpNotFoundResult());
            }
            else
            {
                var vm = converter.EntityToViewmodel(feature);
                return(View(vm));
            }
        }
        [Test] public void GetById_WhenCalled_ShouldReturnItem()
        {
            //Arrange
            EventModel expectedItem = TestsFacade.EventsFacade.BuildEventModelItem();

            var repositoryMock = _mock.Mock <IGenericRepository <EventModel> >();

            repositoryMock
            .Setup(items => items.GetById(expectedItem.Id))
            .Returns(() => expectedItem);

            GenericService <EventModel> service = _mock.Create <GenericService <EventModel> >();

            //Act
            ResultService <EventModel> result = service.GetById(expectedItem.Id);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOf <ResultService <EventModel> >(result);
            Assert.IsTrue(result.Success);
            Assert.IsInstanceOf <EventModel>(result.Value);

            EventModel resultItem = result.Value as EventModel;

            Assert.IsNotNull(resultItem);
            Assert.AreEqual(resultItem.GetHashCode(), expectedItem.GetHashCode());
        }
Beispiel #5
0
        public void GetById_InvalidParameter_ThrowsException()
        {
            var repoGetByIdCalls = productRepoCalls["GetById"];

            try
            {
                // id cannot be less than 1
                var p = productService.GetById(0);
                Assert.Fail("Expected an ArgumentOutOfRangeException, but none thrown.");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOf <ArgumentOutOfRangeException>(ex);
                Assert.AreEqual("id", ((ArgumentOutOfRangeException)ex).ParamName);
                Assert.AreEqual(repoGetByIdCalls, productRepoCalls["GetById"]);
            }
        }
Beispiel #6
0
        public void Generic_GetById_Service(int id)
        {
            var fakeContext = new FakeContext("Generic_GetById_Service");

            fakeContext.FillWithAll();

            using (var context = new MainContext(fakeContext.FakeOptions, fakeContext.FakeConfiguration().Object))
            {
                var repository = new GenericRepository <Product>(context);
                var service    = new GenericService <Product>(repository);

                var contextProduct = context.Products.Find(id);
                var serviceProduct = service.GetById(id);

                Assert.IsType <Product>(serviceProduct);
                Assert.Equal(contextProduct, serviceProduct);
            }
        }
Beispiel #7
0
        public void Generic_Update_Service(int id)
        {
            var fakeContext = new FakeContext("Generic_Update_Service");

            fakeContext.FillWithAll();

            using (var context = new MainContext(fakeContext.FakeOptions, fakeContext.FakeConfiguration().Object))
            {
                var repository = new GenericRepository <Product>(context);
                var service    = new GenericService <Product>(repository);

                var contextProduct = context.Products.Find(id);
                contextProduct.Quantity = 150;
                var response = service.Update(id, contextProduct);

                Assert.Equal("{ Message = Produto alterado com sucesso. }", response.ToString());
                Assert.Equal(150, service.GetById(id).Quantity);
            }
        }
Beispiel #8
0
        public void Test_Create_SaleOutputMessage_Sale(int id)
        {
            var msg         = new MessageFactory();
            var fakeContext = new FakeContext("Create_SaleOutputMessage_Sale");

            fakeContext.FillWithAll();

            using (var context = new MainContext(fakeContext.FakeOptions, fakeContext.FakeConfiguration().Object))
            {
                var repository = new GenericRepository <Sale>(context);
                var service    = new GenericService <Sale>(repository);

                var sale = service.GetById(id);

                var response = msg.Create(MessageType.SaleCreated, sale);

                Assert.IsType <SaleOutputMessage>(response);
                Assert.Equal("SaleCreated", response.MessageTitle);
            }
        }
        [Test] public void GetById_WhenRepositoryThrowException_ShouldReturnError()
        {
            //Arrange
            Exception expectedException = new Exception(Guid.NewGuid().ToString());
            Guid      id = new Guid();

            var repositoryMock = _mock.Mock <IGenericRepository <EventModel> >();

            repositoryMock
            .Setup(items => items.GetById(id))
            .Throws(expectedException);

            GenericService <EventModel> service = _mock.Create <GenericService <EventModel> >();

            //Act
            ResultService <EventModel> result = service.GetById(id);

            //Assert
            AssertResultServiceException <EventModel>(result, expectedException);
        }
        public void Test_Create_WarehouseOutputMessage_Warehouse(int id)
        {
            var msg         = new MessageFactory();
            var fakeContext = new FakeContext("Create_WarehouseOutputMessage_Warehouse");

            fakeContext.FillWith <Product>();

            using (var context = new MainContext(fakeContext.FakeOptions, fakeContext.FakeConfiguration().Object))
            {
                var repository = new GenericRepository <Product>(context);
                var service    = new GenericService <Product>(repository);

                var product = service.GetById(id);

                var response = msg.Create(MessageType.ProductCreated, product);

                Assert.IsType <WarehouseOutputMessage>(response);
                Assert.Equal("ProductCreated", response.MessageTitle);
            }
        }
        [Test] public void GetById_WhenRepositoryReturnsNull_ShouldReturnNotFound()
        {
            //Arrange
            Guid id = new Guid();

            var repositoryMock = _mock.Mock <IGenericRepository <EventModel> >();

            repositoryMock
            .Setup(items => items.GetById(id))
            .Returns(() => null);

            GenericService <EventModel> service = _mock.Create <GenericService <EventModel> >();

            //Act
            ResultService <EventModel> result = service.GetById(id);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsFalse(result.Success);
            Assert.IsNull(result.Value);
            Assert.IsTrue(result.ErrorCode == ErrorCode.NotFound);
        }
Beispiel #12
0
        public ActionResult GetProductDetail(int id)
        {
            var p = service.GetById(id);

            if (p == null)
            {
                return(null);
            }

            var vm = new
            {
                Id           = p.Id,
                Name         = p.Name,
                DefaultLocks = new List <Object>(),
                Versions     = p.Versions.Select(v => new { Id = v.Id, Version = v.Version })
            };

            var allLockProperties = Enum.GetValues(typeof(LockPropertyType));

            foreach (LockPropertyType lockType in allLockProperties)
            {
                if (lockType == LockPropertyType.None)
                {
                    continue;
                }

                if (p.DefaultLockProperties.HasFlag(lockType))
                {
                    vm.DefaultLocks.Add(
                        new
                    {
                        Name  = Enum.GetName(typeof(LockPropertyType), lockType),
                        Value = lockType
                    });
                }
            }

            return(Json(vm, JsonRequestBehavior.AllowGet));
        }
Beispiel #13
0
        public static void Test_Convert_To_Bytes_And_From_Bytes(int id)
        {
            var fakeContext = new FakeContext("Convert_To_Bytes_product");

            fakeContext.FillWith <Product>();

            using (var context = new MainContext(fakeContext.FakeOptions, fakeContext.FakeConfiguration().Object))
            {
                var repository = new GenericRepository <Product>(context);
                var service    = new GenericService <Product>(repository);

                var product         = service.GetById(id);
                var byteProduct     = product.ToJsonBytes();
                var productFromByte = byteProduct.ParseJson <Product>();

                Assert.IsType <byte[]>(byteProduct);
                Assert.IsType <Product>(productFromByte);
                Assert.Equal(product.CreatedAt, productFromByte.CreatedAt);
                Assert.Equal(product.UpdatedAt, productFromByte.UpdatedAt);
                Assert.Equal(product.Name, productFromByte.Name);
                Assert.Equal(product.Sku, productFromByte.Sku);
            }
        }
Beispiel #14
0
        // GET: Dentists/Details/5
        public ActionResult Details(int id)
        {
            PatientsViewModel model = Patient.GetById(id).Map <PatientsViewModel>();

            return(View(model));
        }
        // GET: Dentists/Details/5
        public ActionResult Details(int id)
        {
            TypeServicesViewModel model = Types.GetById(id).Map <TypeServicesViewModel>();

            return(View(model));
        }
        // GET: Dentists/Details/5
        public ActionResult Details(int id)
        {
            UnitsViewModel model = Units.GetById(id).Map <UnitsViewModel>();

            return(View(model));
        }
 public virtual T GetById(int id)
 {
     return(service.GetById(id));
 }