Exemplo n.º 1
0
        public void add_material()
        {
            // Setup
            var mock = new Mock();
            mock.PrepareProfileDB();
            mock.PrepareServicesDB();
            mock.PrepareServiceMaterialsDB();
            mock.PrepareQuotesDB();
            mock.PrepareCustomersDB();
            var materialsDB = mock.PrepareMaterialsDB();
            new Autonomy().Activate();

            var manageMaterialsViewModel = new ManageMaterials.ViewModel();
            var viewModel = new ViewModel();

            // Test
            viewModel.Name = SOME_TEXT;
            viewModel.Description = SOME_TEXT;
            viewModel.Quantity = SOME_DECIMAL_VALUE.ToString();
            viewModel.UnitType = SOME_TEXT;
            viewModel.BaseCost = SOME_DECIMAL_VALUE.ToString();
            viewModel.MarkupPrice = SOME_DECIMAL_VALUE.ToString();
            viewModel.Save.Execute(null);

            // Verify
            var expected = viewModel.IsSaved && manageMaterialsViewModel.Materials.Single().Name == SOME_TEXT;
            Assert.IsTrue(expected);
        }
        public void Can_Add_A_Product_Via_A_Controller()
        {
            var mockEFContext = new Mock<IHypermartContext>();
            var Products = new List<Product>
            {
                new Product{ID = 1,Title = "FirstProduct",Description = "First Product In Database"}
            }.AsQueryable();

            var mockSet = new Mock<DbSet<Product>>();
            mockSet.As<IQueryable<Product>>().Setup(m => m.Provider).Returns(Products.Provider);
            mockSet.As<IQueryable<Product>>().Setup(m => m.Expression).Returns(Products.Expression);
            mockSet.As<IQueryable<Product>>().Setup(m => m.ElementType).Returns(Products.ElementType);
            mockSet.As<IQueryable<Product>>().Setup(m => m.GetEnumerator()).Returns(Products.GetEnumerator());

            mockEFContext.Setup(x => x.Products).Returns(mockSet.Object);

            var prodcontroller = new Open.GI.hypermart.Controllers.ProductsController() { db = mockEFContext.Object };

            var fakeHTTPSession = new TitaniumBunker.PhonySession.FonySession();
            fakeHTTPSession.AddFileUpload(new PhonyUploadFile("Screensjot.jpg", GetResourceAsStrream("TestAPI.img100.jpg"), "JPG"));
            prodcontroller.ControllerContext = fakeHTTPSession.BuildControllerContext(prodcontroller);
            prodcontroller.Url = new UrlHelper(fakeHTTPSession.BuildRequestContext());

            var res = prodcontroller.Create(new Product { ID = 2, Description = "foobar" });
        }
Exemplo n.º 3
0
        public void save_service_with_material()
        {
            // Setup
            var mock = new Mock();
            mock.PrepareProfileDB();
            mock.PrepareMaterialsDB();
            mock.PrepareQuotesDB();
            mock.PrepareCustomersDB();

            var servicesDatabase = mock.PrepareServicesDB();
            var serviceMaterialsDatabase = mock.PrepareServiceMaterialsDB();
            new Autonomy().Activate();

            // Test
            Publish(Messages.REQUEST_SAVE_SERVICE, Mocks.SERVICE_1);

            // Verify
            var serviceSaved = servicesDatabase.Services.Single() == Mocks.SERVICE_1;
            var serviceMaterialsSaved = serviceMaterialsDatabase.ServiceMaterials.Single().ServiceId == Mocks.SERVICE_1.Id &&
                                        serviceMaterialsDatabase.ServiceMaterials.Single().MaterialId == Mocks.SERVICE_1.Materials.Single().Id;
            var expected = serviceSaved &&
                           serviceMaterialsSaved;

            Assert.IsTrue(expected);
        }
Exemplo n.º 4
0
        public void add_service()
        {
            // Setup
            var materialsDatabase = new Mock().PrepareMaterialsPromiseDependencies();
            materialsDatabase.Materials.Add(Mocks.SERVICE_1.Materials.Single());
            new Autonomy().Activate();

            var viewModel = new ViewModel();
            viewModel.Load.Execute(null);

            // Test
            Publish(Messages.REQUEST_SAVE_SERVICE, Mocks.SERVICE_1);

            // Verify
            var expected = viewModel.Services.Contains(Mocks.SERVICE_1);
            Assert.IsTrue(expected);
        }
Exemplo n.º 5
0
        public void read_service_materials()
        {
            // Setup
            ClearSubscriptions();
            var mock = new Mock();
            var serviceMaterialsDatabase = mock.PrepareServiceMaterialsDependencies();
            new Autonomy().Activate();

            // Test
            var service = Mocks.SERVICE_1;
            Publish(Messages.REQUEST_SAVE_SERVICE, service);

            IEnumerable<Material> actualMaterials = null;
            Subscribe(Messages.REQUEST_SERVICE_MATERIALS_MATERIALS_FROM_SERVICE_ID_RESPONSE, obj => actualMaterials = obj as IEnumerable<Material>);
            Publish(Messages.REQUEST_SERVICE_MATERIALS_MATERIALS_FROM_SERVICE_ID, service.Id);

            // Verify
            var expected = actualMaterials.Single() == service.Materials.Single();

            Assert.IsTrue(expected);
        }
Exemplo n.º 6
0
        public void get_material_from_service_material()
        {
            // Setup
            ClearSubscriptions();

            var mock = new Mock();
            var serviceMaterialsDatabase = mock.PrepareServiceMaterialsDependencies();
            new Autonomy().Activate();

            var profileId = new ProfileServer().GetProfile().Id;

            var material = new Material() { Name = SOME_TEXT, UserId = profileId };
            Publish(Messages.REQUEST_SAVE_MATERIAL, material);

            var service = new Service() { Name = SOME_TEXT, UserId = profileId };
            Publish(Messages.REQUEST_SAVE_SERVICE, service);

            var serviceMaterial = new ServiceMaterial()
            {
                MaterialId = material.Id,
                ServiceId = service.Id,
                Quantity = 1,
                UserId = profileId
            };

            Publish(Messages.REQUEST_SAVE_SERVICE_MATERIAL, serviceMaterial);

            // Test
            Material materialResult = null;
            Subscribe(Messages.REQUEST_SERVICE_MATERIAL_RESPONSE, obj => materialResult = obj as Material);
            Publish(Messages.REQUEST_SERVICE_MATERIAL, material.Id);

            // Verify
            var expected = material == materialResult;
            Assert.IsTrue(expected);
        }
Exemplo n.º 7
0
        public void saving_service_material_inserts_item_in_materials_repository()
        {
            // Setup
            ClearSubscriptions();
            var mock = new Mock();
            var materialsDatabase = mock.PrepareMaterialsPromiseDependencies();
            new Autonomy().Activate();

            // Test
            Publish(Messages.REQUEST_SAVE_SERVICE, Mocks.SERVICE_1);

            // Verify
            var materialSaved = materialsDatabase.Materials.Single() == Mocks.SERVICE_1.Materials.Single();
            Assert.IsTrue(materialSaved);
        }