Esempio n. 1
0
        public void GetPropositionMethod()
        {
            GetInMemoryContext().Database.EnsureDeleted();

            PropositionBO prop1 = new PropositionBO()
            {
                Title        = "ost",
                Description  = "beskrivelse",
                CreationDate = DateTime.MinValue,
                EmployeeId   = 2,
                FileId       = 3,
                CustomerId   = 4
            };

            prop1 = GetMockService().Create(prop1);

            PropositionBO prop2 = new PropositionBO()
            {
                Title        = "marmelade",
                Description  = "en ny beskrivelse",
                CreationDate = DateTime.MinValue.Add(TimeSpan.FromMinutes(3)),
                EmployeeId   = 3,
                FileId       = 4,
                CustomerId   = 5
            };

            prop2 = GetMockService().Create(prop2);

            PropositionBO snurf = GetMockService().Get(prop1.Id);

            //Expected results
            Assert.IsNotNull(snurf);
            Assert.AreEqual("ost", snurf.Title);
        }
Esempio n. 2
0
        public void DeletePropositionMethod()
        {
            GetInMemoryContext().Database.EnsureDeleted();

            var prop1 = new PropositionBO()
            {
                Title = "nummerEt"
            };
            var prop2 = new PropositionBO()
            {
                Title = "nummerTo"
            };
            var prop3 = new PropositionBO()
            {
                Title = "nummerTre"
            };
            var prop4 = new PropositionBO()
            {
                Title = "nummerFire"
            };

            prop1 = GetMockService().Create(prop1);
            prop2 = GetMockService().Create(prop2);
            prop3 = GetMockService().Create(prop3);
            prop4 = GetMockService().Create(prop4);

            Assert.IsNotNull(GetMockService().Get(prop3.Id));
            prop3 = GetMockService().Delete(prop3.Id);
            Assert.IsNull(GetMockService().Get(prop3.Id));
        }
Esempio n. 3
0
 public IActionResult Post([FromBody] PropositionBO prop)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     return(Ok(_facade.PropositionService.Create(prop)));
 }
Esempio n. 4
0
 public PropositionBO Create(PropositionBO bo)
 {
     using (var uow = facade.UnitOfWork)
     {
         newProp = uow.PropositionRepository.Create(propConv.Convert(bo));
         uow.Complete();
         return(propConv.Convert(newProp));
     }
 }
Esempio n. 5
0
 public PropositionBO Update(PropositionBO bo)
 {
     using (var uow = facade.UnitOfWork)
     {
         // gets prop from DB that matches the id
         var propFromDb = uow.PropositionRepository.Get(bo.Id);
         propFromDb.Title       = bo.Title;
         propFromDb.Description = bo.Description;
         propFromDb.FileId      = bo.FileId;
         uow.Complete();
         return(propConv.Convert(propFromDb));
     }
 }
Esempio n. 6
0
 public IActionResult Put(int id, [FromBody] PropositionBO prop)
 {
     if (id != prop.Id)
     {
         return(StatusCode(405, "Path id does not match customer ID json object"));
     }
     try
     {
         return(Ok(_facade.PropositionService.Update(prop)));
     }
     catch (InvalidOperationException e)
     {
         return(StatusCode(404, e.Message));
     }
 }
Esempio n. 7
0
        public void CreatePropositionMethod()
        {
            GetInMemoryContext().Database.EnsureDeleted();

            var snurf = new PropositionBO()
            {
                Title        = "ostemad",
                Description  = "ostemad beskrivelse",
                CreationDate = DateTime.MinValue,
                EmployeeId   = 2,
                FileId       = 3,
                CustomerId   = 4
            };

            GetMockService().Create(snurf);

            //Expected results
            Assert.IsNotNull(snurf);
            Assert.AreEqual("ostemad", snurf.Title);
        }
Esempio n. 8
0
 public Proposition Convert(PropositionBO prop)
 {
     if (prop == null)
     {
         return(null);
     }
     {
         return(new Proposition()
         {
             Id = prop.Id,
             Title = prop.Title,
             Description = prop.Description,
             CreationDate = prop.CreationDate,
             Customer = custConv.Convert(prop.Customer),
             CustomerId = prop.CustomerId,
             Employee = empConv.Convert(prop.Employee),
             EmployeeId = prop.EmployeeId,
             FileId = prop.FileId
         });
     }
 }
Esempio n. 9
0
        public void UpdatePropositionMethod()
        {
            GetInMemoryContext().Database.EnsureDeleted();

            var prop = new PropositionBO()
            {
                Title       = "Tit",
                Description = "Desc"
            };

            var newProp = new PropositionBO()
            {
                Title       = "Title",
                Description = "Description"
            };

            prop = GetMockService().Create(prop);

            Assert.AreEqual("Tit", prop.Title);
            prop = GetMockService().Update(GetMockService().Create(newProp));
            Assert.AreEqual("Title", prop.Title);
        }
Esempio n. 10
0
        public void GetAllPropositionsMethod()
        {
            GetInMemoryContext().Database.EnsureDeleted();

            CustomerBO cust1 = new CustomerBO()
            {
                Firstname = "ham her",
                Lastname  = "Fuhlendorff",
                Address   = "testvej1",
                CVR       = 12312312,
                City      = "Kolding",
                Email     = "*****@*****.**",
                Phone     = 12345678,
                ZipCode   = 6000
            };

            cust1 = new CustomerService(GetDalFacadeMock(GetInMemoryContext()).Object).Create(cust1);

            CustomerBO cust2 = new CustomerBO()
            {
                Firstname = "ikke ham her",
                Lastname  = "Meyer",
                Address   = "testvej2222",
                CVR       = 12312312,
                City      = "Esbjerg",
                Email     = "*****@*****.**",
                Phone     = 12345678,
                ZipCode   = 6700
            };
            EmployeeBO employee = new EmployeeBO()
            {
                Firstname  = "Sigurd",
                Lastname   = "Hansen",
                Username   = "******",
                Password   = "******",
                MacAddress = "dfkmgkldfnmg"
            };

            employee = new EmployeeService(GetDalFacadeMock(this.GetInMemoryContext()).Object).Create(employee);

            cust2 = new CustomerService(GetDalFacadeMock(GetInMemoryContext()).Object).Create(cust2);

            PropositionBO prop1 = new PropositionBO()
            {
                Title      = "qwe1",
                CustomerId = cust1.Id,
                EmployeeId = employee.Id
            };

            prop1 = GetMockService().Create(prop1);

            PropositionBO prop2 = new PropositionBO()
            {
                Title      = "qwe2",
                CustomerId = cust1.Id,
                EmployeeId = employee.Id
            };

            prop2 = GetMockService().Create(prop2);

            PropositionBO prop3 = new PropositionBO()
            {
                Title      = "qwe3",
                CustomerId = cust1.Id,
                EmployeeId = employee.Id
            };

            prop3 = GetMockService().Create(prop3);

            PropositionBO prop4 = new PropositionBO()
            {
                Title      = "qwe4",
                CustomerId = cust2.Id,
                EmployeeId = employee.Id
            };

            prop4 = GetMockService().Create(prop4);

            PropositionBO prop5 = new PropositionBO()
            {
                Title      = "qwe5",
                CustomerId = cust2.Id,
                EmployeeId = 1
            };

            prop5 = GetMockService().Create(prop5);

            PropositionBO prop6 = new PropositionBO()
            {
                Title      = "qwe6",
                CustomerId = cust2.Id,
                EmployeeId = employee.Id
            };

            prop6 = GetMockService().Create(prop6);

            List <PropositionBO> allProps = GetMockService().GetAllById(cust1.Id);

            Assert.IsNotNull(allProps);
            Assert.AreEqual(3, allProps.Count);
            Assert.AreEqual(cust1.Firstname, allProps.Find(x => x.Title == "qwe3").Customer.Firstname);
            Assert.IsNull(allProps.Find(x => x.Title == "qwe4"));
        }