コード例 #1
0
        private static void RemovePeople()
        {
            IList <Person> peopleToDelete;

            using (var db = new AbsenceManagementContext()) {
                db.Database.Log = Console.WriteLine;
                var pplRepo           = new EFDisconnectedPersonRepository(db);
                var peopleToDeleteIds = GetPeople().Select(p => p.DataSourceId);
                peopleToDelete = pplRepo.GetAll().Where(p => peopleToDeleteIds.Contains(p.DataSourceId)).ToList();
            }

            using (var db = new AbsenceManagementContext()) {
                db.Database.Log = Console.WriteLine;
                var pplRepo = new EFDisconnectedPersonRepository(db);
                foreach (var personToDelete in peopleToDelete)
                {
                    pplRepo.Delete(personToDelete);
                }
            }

            // NOTE: deleting could very well be done by going off to a stored procedure,
            // because retrieving and then doing another query for deletion
            // seems a bit much
            // Depends on the scenario
        }
コード例 #2
0
 private static void ListAllPeople()
 {
     using (var db = new AbsenceManagementContext()) {
         db.Database.Log = Console.WriteLine;
         var repo = new EFDisconnectedPersonRepository(db);
         PrintPerson(repo.GetAll().ToArray());
     }
 }
コード例 #3
0
        public void Can_Add()
        {
            // Arrange
            var sut = new EFDisconnectedPersonRepository(
                EFTestData.GetTransientAbsenceManagementContext()
                );
            var user = PersonBuilder.CreatePerson("John", "Doe").Build();

            // Act
            sut.Add(user);
            var actual = sut.GetAll().FirstOrDefault(p => p.FirstName.Equals("John"));

            // Assert
            Assert.Equal(1, sut.GetAll().Count());
            Assert.NotNull(actual);
            Assert.Equal(user.FirstName, actual.FirstName);
            Assert.Equal(user.LastName, actual.LastName);
        }
コード例 #4
0
        public void Can_Update()
        {
            using (var ctx = EFTestData.GetPersistentAbsenceManagentContext()) {
                // Arrange
                var sut    = new EFDisconnectedPersonRepository(ctx);
                var userId = sut.GetAll().FirstOrDefault().Id;

                // Act
                var actual = PersonBuilder.CreatePerson("Johnnie", "Doe").Build();
                TestData.SetPrivateProperty(actual, nameof(Person.Id), userId);
                sut.Update(actual);

                // Assert
                Assert.Equal(ctx.People.Count(), sut.GetAll().Count());
                Assert.NotNull(actual);
                Assert.Equal("Johnnie", actual.FirstName);
                Assert.Equal("Doe", actual.LastName);
            }
        }
コード例 #5
0
        private static void InsertRelation()
        {
            using (var db = new AbsenceManagementContext()) {
                db.Database.Log = Console.WriteLine;
                var pplRepo = new EFDisconnectedPersonRepository(db);
                var relRepo = new EFDisconnectedRelationRepository(db);

                var janeDoe = pplRepo.GetAll()
                              .FirstOrDefault(p => p.FirstName == "Jane");
                var johnDoe = pplRepo.GetAll()
                              .FirstOrDefault(p => p.FirstName == "John");
                var relation = RelationBuilder
                               .CreateRelation(RelationType.ManagerToSubordinate)
                               .ForMaster(janeDoe)
                               .WithSlave(johnDoe)
                               .Build();
                relRepo.Add(relation);
            }
        }
コード例 #6
0
        public void Can_GetById()
        {
            using (var ctx = EFTestData.GetPersistentAbsenceManagentContext()) {
                // Arrange
                var sut    = new EFDisconnectedPersonRepository(ctx);
                var userId = sut.GetAll().FirstOrDefault().Id;

                // Act
                var user = sut.GetById(userId);

                // Assert
                Assert.NotNull(user);
                Assert.Equal(userId, user.Id);
            }
        }
コード例 #7
0
        public void Can_Delete_WithId()
        {
            using (var ctx = EFTestData.GetPersistentAbsenceManagentContext()) {
                // Arrange
                var sut    = new EFDisconnectedPersonRepository(ctx);
                var userId = sut.GetAll().FirstOrDefault().Id;

                // Act
                sut.Delete(userId);
                var user = ctx.People.FirstOrDefault(p => p.Id.Equals(userId));

                // Assert
                Assert.Null(user);
            }
        }