Exemple #1
0
        public void GetOfficesByEmployeeId_ShouldReturn()
        {
            var officesTestData = new List <EmployeeOffice>()
            {
                new EmployeeOffice {
                    Id = 1, EmployeeId = 2
                },
                new EmployeeOffice {
                    Id = 2, Deleted = true, EmployeeId = 2
                },
                new EmployeeOffice {
                    Id = 3, EmployeeId = 3
                }
            };
            var offices   = MockHelper.MockDbSet(officesTestData);
            var dbContext = new Mock <IAppDbContext>();

            dbContext.Setup(m => m.EmployeeOffices).Returns(offices.Object);
            dbContext.Setup(d => d.Set <EmployeeOffice>()).Returns(offices.Object);
            var factory = new Mock <IDbContextFactory>();

            factory.Setup(m => m.CreateDbContext()).Returns(dbContext.Object);
            var controller = new EmployeeOfficesController(factory.Object);
            var result     = controller.GetEmployeeOfficeByEmployeeId(2) as OkNegotiatedContentResult <IEnumerable <EmployeeOfficeDTO> >;

            Assert.AreEqual(1, result.Content.Count());
        }
Exemple #2
0
        public void GetOfficeById_ShouldReturn()
        {
            var officesTestData = new List <EmployeeOffice>()
            {
                new EmployeeOffice {
                    Id = 1, EmployeeId = 2
                },
                new EmployeeOffice {
                    Id = 2, Deleted = true, EmployeeId = 2
                },
                new EmployeeOffice {
                    Id = 3, EmployeeId = 3
                }
            };
            var offices = MockHelper.MockDbSet(officesTestData);

            offices.Setup(d => d.Find(It.IsAny <object>())).Returns <object[]>((keyValues) => { return(offices.Object.SingleOrDefault(product => product.Id == (int)keyValues.Single())); });

            var dbContext = new Mock <IAppDbContext>();

            dbContext.Setup(m => m.EmployeeOffices).Returns(offices.Object);
            dbContext.Setup(d => d.Set <EmployeeOffice>()).Returns(offices.Object);
            var factory = new Mock <IDbContextFactory>();

            factory.Setup(m => m.CreateDbContext()).Returns(dbContext.Object);
            var controller = new EmployeeOfficesController(factory.Object);
            var result     = controller.GetEmployeeOffice(1) as OkNegotiatedContentResult <EmployeeOfficeDTO>;

            Assert.AreEqual(1, result.Content.Id);
            Assert.AreEqual(2, result.Content.EmployeeId);
        }
Exemple #3
0
        public void PostOffice_ShoulAddOffice()
        {
            var officesTestData = new List <EmployeeOffice>()
            {
                new EmployeeOffice {
                    Id = 1, EmployeeId = 2
                },
                new EmployeeOffice {
                    Id = 2, Deleted = true, EmployeeId = 2
                },
                new EmployeeOffice {
                    Id = 3, EmployeeId = 3
                }
            };
            var offices = MockHelper.MockDbSet(officesTestData);

            offices.Setup(d => d.Find(It.IsAny <object>())).Returns <object[]>((keyValues) => { return(offices.Object.SingleOrDefault(product => product.Id == (int)keyValues.Single())); });
            offices.Setup(d => d.Add(It.IsAny <EmployeeOffice>())).Returns <EmployeeOffice>((contact) =>
            {
                officesTestData.Add(contact);
                offices = MockHelper.MockDbSet(officesTestData);
                return(contact);
            });

            var dbContext = new Mock <IAppDbContext>();

            dbContext.Setup(m => m.EmployeeOffices).Returns(offices.Object);
            dbContext.Setup(d => d.Set <EmployeeOffice>()).Returns(offices.Object);

            dbContext.Setup(d => d.ExecuteStoredProcedure <int>(It.IsAny <string>(), It.IsAny <object[]>()))
            .Returns <string, object[]>((query, parameters) =>
            {
                List <int> list = new List <int>();
                if (query.Contains("NewTableId"))
                {
                    int i = offices.Object.Max(d => d.Id) + 1;
                    list.Add(i);
                }
                else
                {
                    list.Add(0);
                }
                return(list);
            });

            var factory = new Mock <IDbContextFactory>();

            factory.Setup(m => m.CreateDbContext()).Returns(dbContext.Object);

            EmployeeOffice passport = new EmployeeOffice {
                Id = 0, EmployeeId = 3
            };
            var controller = new EmployeeOfficesController(factory.Object);
            var result     = controller.PostEmployeeOffice(passport.ToDTO()) as CreatedAtRouteNegotiatedContentResult <EmployeeOfficeDTO>;

            Assert.IsNotNull(result);
            Assert.AreEqual(4, result.Content.Id);
            Assert.AreEqual(3, result.Content.EmployeeId);
        }