Exemplo n.º 1
0
        public void Add(UserInfo userInfo)
        {
            if (userInfo == null)
            {
                return;
            }

            _efRepository.Add(userInfo);
        }
        public void Add(JsApiTicket jsApiTicket)
        {
            if (jsApiTicket == null)
            {
                return;
            }

            _efRepository.Add(jsApiTicket);
        }
Exemplo n.º 3
0
        public static bool AddEmployee(Employees NewEmployee)
        {
            EFRepository <Employees> EmployeesRepo = new EFRepository <Employees>();

            EmployeesRepo.Add(NewEmployee);

            GlobalUnitOfWork.Commit();
            return(true);
        }
Exemplo n.º 4
0
        public void Add(AccessToken accessToken)
        {
            if (accessToken == null)
            {
                throw new Exception("保存的AccessToken对象为空");
            }

            _efRepository.Add(accessToken);
        }
Exemplo n.º 5
0
        public void Add_Throws_On_Null_Individual()
        {
            //Arrange
            var mockContext = new Mock <FamilyTreeContext>();
            var rep         = new EFRepository <Individual>(mockContext.Object);

            //Act, Assert
            Assert.Throws <ArgumentNullException>(() => rep.Add(null));
        }
Exemplo n.º 6
0
        public void HelloWorld1()
        {
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load("Definitions\\HelloWorld1.xml");

            using (var unitWork = UnitOfWork.Start())
            {
                ProcessDefinitionCreationContext creationContext = new ProcessDefinitionCreationContext();
                ProcessDefinition processDefinition = creationContext.CreateProcessDefinition(xmlDocument);
                creationContext.ResolveReferences();

                Assert.AreEqual("Hello world 1", processDefinition.Name);
                Assert.AreEqual("This is the simples process.", processDefinition.Description);
                Assert.AreEqual(3, processDefinition.Nodes.Count);
                Node          start = null, end = null;
                ActivityState activityState = null;
                foreach (Node node in processDefinition.Nodes)
                {
                    if (node.Name == "start")
                    {
                        start = node;
                    }
                    else if (node.Name == "first activity state")
                    {
                        activityState = node as ActivityState;
                    }
                    else if (node.Name == "end")
                    {
                        end = node;
                    }
                }
                Assert.IsNotNull(start);
                Assert.AreEqual(1, start.LeavingTransitions.Count);
                foreach (Transition transition in start.LeavingTransitions)
                {
                    Assert.AreEqual(start, transition.From);
                    Assert.AreEqual(activityState, transition.To);
                }

                Assert.IsNotNull(activityState);
                Assert.AreEqual("this is the first state", activityState.Description);
                Assert.IsNotNull(activityState.AssignmentDelegation);

                Assert.AreEqual(1, activityState.LeavingTransitions.Count);
                foreach (Transition transition in activityState.LeavingTransitions)
                {
                    Assert.AreEqual(activityState, transition.From);
                    Assert.AreEqual(end, transition.To);
                }

                var processBlockRepository = new EFRepository <ProcessBlock>();
                processBlockRepository.Add(processDefinition);
                unitWork.Flush();
            }
        }
Exemplo n.º 7
0
        public void InitOrganAndBuildDBSchema()
        {
            using (var unitWork = UnitOfWork.Start())
            {
                User user = new User("hugo");
                user.FirstName = "Hugo";
                user.LastName  = "Cheng";
                user.Email     = "*****@*****.**";

                User user1 = new User("jimmy");
                user1.FirstName = "Jimmy";
                user1.LastName  = "Yang";
                user1.Email     = "*****@*****.**";

                User user2 = new User("jenny");
                user2.FirstName = "jenny";
                user2.LastName  = "Chen";
                user2.Email     = "*****@*****.**";

                var userRepository = new EFRepository <User>();
                userRepository.Add(user);
                userRepository.Add(user1);
                userRepository.Add(user2);

                Group group = new Group("C#");
                group.Name = "C# Team";

                var groupRepository = new EFRepository <Group>();
                groupRepository.Add(group);

                Membership membership = new Membership(SequentialGuid.NewGuid());
                membership.Type  = "hierarchy";
                membership.Role  = "Member";
                membership.User  = user;
                membership.Group = group;

                Membership membership1 = new Membership(SequentialGuid.NewGuid());
                membership1.Type  = "hierarchy";
                membership1.Role  = "boss";
                membership1.User  = user1;
                membership1.Group = group;

                Membership membership2 = new Membership(SequentialGuid.NewGuid());
                membership2.Type  = "hierarchy";
                membership2.Role  = "hr-responsible";
                membership2.User  = user2;
                membership2.Group = group;

                var membershipRepository = new EFRepository <Membership>();
                membershipRepository.Add(membership);
                membershipRepository.Add(membership1);
                membershipRepository.Add(membership2);

                unitWork.Flush();
            }
        }
Exemplo n.º 8
0
        public static bool AddEmployee(Employees NewEmployee)
        {
            EFRepository<Employees> EmployeesRepo = new EFRepository<Employees>();

            EmployeesRepo.Add(NewEmployee);

            GlobalUnitOfWork.Commit();
            return true;

        }
Exemplo n.º 9
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(ManagerLogInfo model)
        {
            if (model == null)
            {
                return(0);
            }

            _efRepository.Add(model);
            return(model.Id);
        }
Exemplo n.º 10
0
        public bool Add(PaymentInfo paymentInfo)
        {
            if (paymentInfo == null)
            {
                return(false);
            }

            _efRepository.Add(paymentInfo);
            return(true);
        }
Exemplo n.º 11
0
        public int AddAuthor(Author item)
        {
            EFRepository <Author> rep = new EFRepository <Author>(db);

            rep.Add(item);

            //db.Authors.Add(item);
            db.SaveChanges();

            return(item.AuthorID);
        }
Exemplo n.º 12
0
        /// <summary>
        ///     增加一条数据
        /// </summary>
        public int Add(PaymentInfo model)
        {
            if (model != null)
            {
                _efRepository.Add(model);

                return(model.Id);
            }

            return(0);
        }
Exemplo n.º 13
0
        public int Add(AppInfo appInfo)
        {
            if (appInfo == null)
            {
                return(0);
            }

            appInfo.CreateDate = DateTime.Now;

            _efRepository.Add(appInfo);
            return(appInfo.Id);
        }
Exemplo n.º 14
0
        public void AddShould_CallDbContextSetAdded()
        {
            var dbContextMock = new Mock <IFindAndBookContext>();

            var repository = new EFRepository <FakeEFRepository>(dbContextMock.Object);

            var entity = new Mock <FakeEFRepository>();

            repository.Add(entity.Object);

            dbContextMock.Verify(c => c.SetAdded(entity.Object), Times.Once);
        }
Exemplo n.º 15
0
        public void Throw_WhenEntityIsNull()
        {
            // Arrange
            var mockedDbContext = new Mock <IMeetMeDbContext>();
            var repo            = new EFRepository <Comment>(mockedDbContext.Object);

            // Act
            var ex = Assert.Throws <ArgumentNullException>(() => repo.Add(null));

            // Assert
            Assert.That(ex.Message.Contains("Entity"));
        }
        public void CreateNews_WithIncorrectData_ShouldThrow()
        {
            // Arrange
            this.CleanUpDatabase();
            var listWithNews = new List<News>();
            var repo = new EFRepository<News>(this.dbcontext);
            var new1 = new News() { Content = null, Title = null, PublishedAt = DateTime.Now };

            // Act
            repo.Add(new1);
            repo.SaveChanges();
        }
Exemplo n.º 17
0
        public string AddNotice(string Content)
        {
            try
            {
                Notice Notice = new Notice();

                ApplicationUser user = _userManager.GetUserAsync(User).Result;

                Notice.NoticeContent = Content;

                Notice.MasjidId  = user.MasjidId;
                Notice.IsHidden  = false;
                Notice.CreatedId = user.Id;

                Repository.Add(Notice);

                return("Successful");
            }
            catch (Exception ex)
            {
                return("Failed " + ex.Message);
            }
        }
Exemplo n.º 18
0
        public void FindAll_Should_Return_All_Record_In_Table()
        {
            EFRepository <Function, string> EFRepository = new EFRepository <Function, string>(_context);

            EFRepository.Add(new Function()
            {
                Id        = "USER",
                Name      = "Test",
                Status    = Status.Active,
                SortOrder = 1
            });
            EFRepository.Add(new Function()
            {
                Id        = "ROLE",
                Name      = "Test",
                Status    = Status.Active,
                SortOrder = 2
            });
            _unitOfWork.Commit();

            List <Function> functions = EFRepository.FindAll().ToList();

            Assert.Equal(2, functions.Count);
        }
Exemplo n.º 19
0
        public static void Add_edit()
        {
            var c = new Post()
            {
                CreatedDate = DateTime.Now,
                Title       = "Csharp",
                Body        = "Csharp in a nutshell"
            };

            var post = new EFRepository <BlogDBContext, Post>();

            post.Add(c);
            c.Title = "EntityFramework";
            post.Edit(c);
        }
        public void CreateNews_WithIncorrectData_ShouldThrow()
        {
            // Arrange
            this.CleanUpDatabase();
            var listWithNews = new List <News>();
            var repo         = new EFRepository <News>(this.dbcontext);
            var new1         = new News()
            {
                Content = null, Title = null, PublishedAt = DateTime.Now
            };

            // Act
            repo.Add(new1);
            repo.SaveChanges();
        }
Exemplo n.º 21
0
        public void ThrowArgumentNullException_WhenArgumentIsNull()
        {
            //Arrange
            var mockedSet       = new Mock <DbSet <IDestination> >();
            var mockedDbContext = new Mock <ITravelAdvisorDbContext>();

            //Act
            mockedDbContext.Setup(mock => mock.Set <IDestination>()).Returns(mockedSet.Object);
            var          repository = new EFRepository <IDestination>(mockedDbContext.Object);
            IDestination entity     = null;

            //Assert
            Assert.That(() => repository.Add(entity),
                        Throws.InstanceOf <ArgumentNullException>().With.Message.Contains("Entity cannot be null!"));
        }
Exemplo n.º 22
0
        public void SavePermission(List <PermissionViewModel> permissionVms, Guid roleId)
        {
            var permissions   = Mapper.Map <List <PermissionViewModel>, List <Permission> >(permissionVms);
            var oldPermission = _permissionRepository.FindAll().Where(x => x.RoleId == roleId).ToList();

            if (oldPermission.Count > 0)
            {
                _permissionRepository.RemoveMultiple(oldPermission);
            }
            foreach (var permission in permissions)
            {
                _permissionRepository.Add(permission);
            }
            _unitOfWork.Commit();
        }
Exemplo n.º 23
0
        public void Delete_Deletes_Record()
        {
            var newCustomer = new Customer
            {
                FirstName = ("John_DELETE_ME_" + DateTime.Now),
                LastName = ("Doe_DELETE_ME_" + DateTime.Now),
                StreetAddress1 = "This record was inserted for deletion",
                City = "Fictional city",
                State = "LA",
                ZipCode = "12345"
            };

            //Re-usable query to query for the matching record.
            var queryForCustomer = new Func<EFRepository<Customer>, Customer>
                (
                x => (from cust in x
                      where cust.FirstName == newCustomer.FirstName && cust.LastName == newCustomer.LastName
                      select cust).FirstOrDefault()
                );

            using (var scope = new UnitOfWorkScope())
            {
                var customerRepository = new EFRepository<Customer>();
                var recordCheckResult = queryForCustomer(customerRepository);
                Assert.That(recordCheckResult, Is.Null);

                customerRepository.Add(newCustomer);
                scope.Commit();
            }

            //Retrieve the record for deletion.
            using (var scope = new UnitOfWorkScope())
            {
                var customerRepository = new EFRepository<Customer>();
                var customerToDelete = queryForCustomer(customerRepository);
                Assert.That(customerToDelete, Is.Not.Null);
                customerRepository.Delete(customerToDelete);
                scope.Commit();
            }

            //Ensure customer record is deleted.
            using (new UnitOfWorkScope())
            {
                var customerRepository = new EFRepository<Customer>();
                var recordCheckResult = queryForCustomer(customerRepository);
                Assert.That(recordCheckResult, Is.Null);
            }
        }
Exemplo n.º 24
0
        public void Delete_Deletes_Record()
        {
            var newCustomer = new Customer
            {
                FirstName      = ("John_DELETE_ME_" + DateTime.Now),
                LastName       = ("Doe_DELETE_ME_" + DateTime.Now),
                StreetAddress1 = "This record was inserted for deletion",
                City           = "Fictional city",
                State          = "LA",
                ZipCode        = "12345"
            };

            //Re-usable query to query for the matching record.
            var queryForCustomer = new Func <EFRepository <Customer>, Customer>
                                   (
                x => (from cust in x
                      where cust.FirstName == newCustomer.FirstName && cust.LastName == newCustomer.LastName
                      select cust).FirstOrDefault()
                                   );

            using (var scope = new UnitOfWorkScope())
            {
                var customerRepository = new EFRepository <Customer>();
                var recordCheckResult  = queryForCustomer(customerRepository);
                Assert.That(recordCheckResult, Is.Null);

                customerRepository.Add(newCustomer);
                scope.Commit();
            }

            //Retrieve the record for deletion.
            using (var scope = new UnitOfWorkScope())
            {
                var customerRepository = new EFRepository <Customer>();
                var customerToDelete   = queryForCustomer(customerRepository);
                Assert.That(customerToDelete, Is.Not.Null);
                customerRepository.Delete(customerToDelete);
                scope.Commit();
            }

            //Ensure customer record is deleted.
            using (new UnitOfWorkScope())
            {
                var customerRepository = new EFRepository <Customer>();
                var recordCheckResult  = queryForCustomer(customerRepository);
                Assert.That(recordCheckResult, Is.Null);
            }
        }
Exemplo n.º 25
0
        public void HolidayTest()
        {
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load("Definitions\\Holiday.xml");

            using (var unitWork = UnitOfWork.Start())
            {
                ProcessDefinitionCreationContext creationContext = new ProcessDefinitionCreationContext();
                ProcessDefinition processDefinition = creationContext.CreateProcessDefinition(xmlDocument);
                creationContext.ResolveReferences();

                Assert.AreEqual(1, processDefinition.ChildBlocks.Count);
                ProcessBlock concurrentProcessBlock = processDefinition.ChildBlocks.First();

                Node          fork = null, join = null;
                ActivityState hrNotify = null, approvalNotify = null;
                foreach (Node node in concurrentProcessBlock.Nodes)
                {
                    if (node.Name == "approved holiday fork")
                    {
                        fork = node;
                    }
                    else if (node.Name == "join before finish")
                    {
                        join = node;
                    }
                    else if (node.Name == "HR notification")
                    {
                        hrNotify = node as ActivityState;
                    }
                    else if (node.Name == "approval notification")
                    {
                        approvalNotify = node as ActivityState;
                    }
                }

                Assert.IsNotNull(fork);
                Assert.IsNotNull(join);
                Assert.IsNotNull(hrNotify);
                Assert.IsNotNull(approvalNotify);
                Assert.IsNotNull(fork.LeavingTransitions.First().To);

                var processBlockRepository = new EFRepository <ProcessBlock>();
                processBlockRepository.Add(processDefinition);
                unitWork.Flush();
            }
        }
Exemplo n.º 26
0
        public void CreateMemberShip()
        {
            using (var unitWork = UnitOfWork.Start())
            {
                var userRepository = new EFRepository <User>();

                Membership membership = new Membership(SequentialGuid.NewGuid());
                membership.Role = "What";
                membership.Type = "Who";
                membership.User = userRepository.Single(s => s.FirstName == "Hugo");

                var membershipRepository = new EFRepository <Membership>();
                membershipRepository.Add(membership);
                unitWork.Flush();
            }
        }
Exemplo n.º 27
0
        public void CallStateFactory_Once()
        {
            // Arrange
            var mockedComment    = new Mock <Comment>();
            var mockedDbContext  = new Mock <IMeetMeDbContext>();
            var mockedEntryState = new Mock <IEntryState <Comment> >();

            mockedEntryState.Object.State = EntityState.Deleted;
            mockedDbContext.Setup(x => x.GetState(mockedComment.Object)).Returns(mockedEntryState.Object);
            var repo = new EFRepository <Comment>(mockedDbContext.Object);

            // Act
            repo.Add(mockedComment.Object);

            // Assert
            mockedDbContext.Verify(x => x.GetState(mockedComment.Object), Times.Once);
        }
Exemplo n.º 28
0
        public void Add_Should_Have_Record_When_Insert()
        {
            EFRepository <Function, string> EFRepository = new EFRepository <Function, string>(_context);

            EFRepository.Add(new Function()
            {
                Id        = "USER",
                Name      = "Test",
                Status    = Status.Active,
                SortOrder = 1
            });
            _unitOfWork.Commit();

            Function function = EFRepository.FindById("USER");

            Assert.NotNull(function);
        }
Exemplo n.º 29
0
        public void FindByIdAsync_Should_Return_True_Record_In_Table()
        {
            EFRepository <Function, string> EFRepository = new EFRepository <Function, string>(_context);

            EFRepository.Add(new Function()
            {
                Id        = "USER",
                Name      = "Test",
                Status    = Status.Active,
                SortOrder = 1
            });
            _unitOfWork.Commit();

            Function function = EFRepository.FindById("USER");

            Assert.Equal("Test", function.Name);
        }
        public void Delete_ExistingNews_ShouldDeleteTheNew()
        {
            // Arrange
            this.CleanUpDatabase();
            var listWithNews = new List<News>();
            var repo = new EFRepository<News>(this.dbcontext);
            var new1 = new News() { Content = "Content of new", Title = "Title 1", PublishedAt = DateTime.Now };

            // Act
            repo.Add(new1);
            repo.SaveChanges();
            var newsInDb = repo.All().ToArray();
            repo.Delete(newsInDb[0]);
            repo.SaveChanges();

            // Assert
            Assert.AreEqual(0, repo.All().ToList().Count());
        }
Exemplo n.º 31
0
        public void Commit_Should_Success_When_Save_Data()
        {
            EFRepository <Function, string> efRepository = new EFRepository <Function, string>(_context);
            EFUnitOfWork unitOfWork = new EFUnitOfWork(_context);

            efRepository.Add(new Function()
            {
                Id        = "USER",
                Name      = "Test",
                Status    = Status.Active,
                SortOrder = 1
            });
            unitOfWork.Commit();

            List <Function> functions = efRepository.FindAll().ToList();

            Assert.Single(functions);
        }
Exemplo n.º 32
0
        public void HelloWorld2()
        {
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load("Definitions\\HelloWorld2.xml");

            using (var unitWork = UnitOfWork.Start())
            {
                ProcessDefinitionCreationContext creationContext = new ProcessDefinitionCreationContext();
                ProcessDefinition processDefinition = creationContext.CreateProcessDefinition(xmlDocument);
                creationContext.ResolveReferences();

                Node          start = null, end = null;
                ActivityState activityState = null;
                foreach (Node node in processDefinition.Nodes)
                {
                    if (node.Name == "start")
                    {
                        start = node;
                    }
                    else if (node.Name == "first activity state")
                    {
                        activityState = node as ActivityState;
                    }
                    else if (node.Name == "end")
                    {
                        end = node;
                    }
                }
                Assert.IsNotNull(start);
                Assert.IsNotNull(activityState);
                Assert.IsNotNull(activityState.AssignmentDelegation);

                DelegationDef delegationDef = activityState.AssignmentDelegation;
                Assert.AreEqual("ActorAssignment", delegationDef.ClassName);

                Assert.AreEqual("<cfg><parametername=\"expression\">processInitiator</parameter></cfg>", Regex.Replace(delegationDef.Configuration, @"\s|\t|\n|\r", ""));

                var processBlockRepository = new EFRepository <ProcessBlock>();
                processBlockRepository.Add(processDefinition);
                unitWork.Flush();
            }
        }
        public void CreateNews_WithCorrectData_ShouldCreateNewsSuccessfully()
        {
            // Arrange
            this.CleanUpDatabase();
            var listWithNews = new List<News>();
            var repo = new EFRepository<News>(this.dbcontext);
            var new1 = new News() { Content = "Content 1", Title = "Title 1", PublishedAt = DateTime.Now };

            // Act
            repo.Add(new1);
            repo.SaveChanges();
            var newsInDb = repo.All().ToArray();

            // Assert
            Assert.AreEqual(1, newsInDb.Count());
            Assert.AreEqual(new1.Title, newsInDb[0].Title);
            Assert.AreEqual(new1.Content, newsInDb[0].Content);
            Assert.AreEqual(new1.PublishedAt.ToString(), newsInDb[0].PublishedAt.ToString());
        }
Exemplo n.º 34
0
        public void FindSingle_Should_Return_One_Record_If_Condition_Is_Match()
        {
            EFRepository <Function, string> EFRepository = new EFRepository <Function, string>(_context);

            Function function = new Function()
            {
                Id        = "USER",
                Name      = "Test",
                Status    = Status.Active,
                SortOrder = 1
            };

            EFRepository.Add(function);
            _unitOfWork.Commit();

            Function result = EFRepository.FindSingle(x => x.Name == "Test");

            Assert.NotNull(result);
        }
Exemplo n.º 35
0
        public void Save_New_Customer_Saves_Customer_When_UnitOfWork_Is_Committed()
        {
            var rnd         = new Random();
            var newCustomer = new Customer
            {
                FirstName      = ("John_" + rnd.Next(0, 30000)),
                LastName       = ("Doe_" + rnd.Next(0, 30000)),
                StreetAddress1 = "This record was inserted via a test",
                City           = "Fictional city",
                State          = "LA",
                ZipCode        = "12345"
            };

            var queryForCustomer = new Func <EFRepository <Customer>, Customer>
                                   (
                x => (from cust in x
                      where cust.FirstName == newCustomer.FirstName && cust.LastName == newCustomer.LastName
                      select cust).FirstOrDefault()
                                   );

            using (var scope = new UnitOfWorkScope())
            {
                var customerRepository = new EFRepository <Customer>();
                var recordCheckResult  = queryForCustomer(customerRepository);
                Assert.That(recordCheckResult, Is.Null);

                customerRepository.Add(newCustomer);
                scope.Commit();
            }

            //Starting a completely new unit of work and repository to check for existance.
            using (var scope = new UnitOfWorkScope())
            {
                var customerRepository = new EFRepository <Customer>();
                var recordCheckResult  = queryForCustomer(customerRepository);
                Assert.That(recordCheckResult, Is.Not.Null);
                Assert.That(recordCheckResult.FirstName, Is.EqualTo(newCustomer.FirstName));
                Assert.That(recordCheckResult.LastName, Is.EqualTo(newCustomer.LastName));
                customerRepository.Delete(recordCheckResult); //Deleting record after verification.
                scope.Commit();
            }
        }
Exemplo n.º 36
0
        public void Save_New_Customer_Saves_Customer_When_UnitOfWork_Is_Committed()
        {
            var rnd = new Random();
            var newCustomer = new Customer
            {
                FirstName = ("John_" + rnd.Next(0, 30000)),
                LastName = ("Doe_" + rnd.Next(0, 30000)),
                StreetAddress1 = "This record was inserted via a test",
                City = "Fictional city",
                State = "LA",
                ZipCode = "12345"
            };

            var queryForCustomer = new Func<EFRepository<Customer>, Customer>
                (
                x => (from cust in x
                      where cust.FirstName == newCustomer.FirstName && cust.LastName == newCustomer.LastName
                      select cust).FirstOrDefault()
                );

            using (var scope = new UnitOfWorkScope())
            {
                var customerRepository = new EFRepository<Customer>();
                var recordCheckResult = queryForCustomer(customerRepository);
                Assert.That(recordCheckResult, Is.Null);

                customerRepository.Add(newCustomer);
                scope.Commit();
            }

            //Starting a completely new unit of work and repository to check for existance.
            using (var scope = new UnitOfWorkScope())
            {
                var customerRepository = new EFRepository<Customer>();
                var recordCheckResult = queryForCustomer(customerRepository);
                Assert.That(recordCheckResult, Is.Not.Null);
                Assert.That(recordCheckResult.FirstName, Is.EqualTo(newCustomer.FirstName));
                Assert.That(recordCheckResult.LastName, Is.EqualTo(newCustomer.LastName));
                customerRepository.Delete(recordCheckResult); //Deleting record after verification.
                scope.Commit();
            }
        }
Exemplo n.º 37
0
 public void Initialize()
 {
     Context = new ParikshaContext();
     EfUoW = new EFUnitOfWork(Context);
     UserRepository = new EFRepository<UserDetail>(EfUoW, Context);
     QuestionRepository = new EFRepository<Question>(EfUoW, Context);
     StandardRepository = new EFRepository<Standard>(EfUoW, Context);
     SubjectRepository = new EFRepository<Subject>(EfUoW, Context);
     User = new UserDetail { UserRole = UserRole.Admin, Password = "******", Name = "ashutosh", DateOfCreation = DateTime.UtcNow };
     Standard = new Standard { StandardName = "First" };
     Subject = new Subject { SubjectName = "Mathematics", SubjectCategory = "Algebra", Standard = Standard };
     UserRepository.Add(User);
     StandardRepository.Add(Standard);
     SubjectRepository.Add(Subject);
     EfUoW.Commit();
 }
        public void UpdateNews_WithIncorrectData_ShouldThrow()
        {
            // Arrange
            this.CleanUpDatabase();
            var listWithNews = new List<News>();
            var repo = new EFRepository<News>(this.dbcontext);
            var new1 = new News() { Content = "Content of new", Title = "Title 1", PublishedAt = DateTime.Now };

            // Act
            repo.Add(new1);
            repo.SaveChanges();
            var newsInDb = repo.All().ToArray();
            string newTitle = null;
            newsInDb[0].Title = newTitle;
            repo.Update(newsInDb[0]);
            repo.SaveChanges();
            var latestNewsInDb = repo.All().ToArray();

            // Assert
            Assert.AreEqual(1, newsInDb.Count());
            Assert.AreEqual(new1.Title, latestNewsInDb[0].Title);
            Assert.AreEqual(new1.Content, latestNewsInDb[0].Content);
        }
Exemplo n.º 39
0
        public void Save_Does_Not_Save_New_Customer_When_UnitOfWork_Is_Aborted()
        {
            var rnd = new Random();
            var newCustomer = new Customer
            {
                FirstName = ("John_" + rnd.Next(30001, 50000)),
                LastName = ("Doe_" + rnd.Next(30001, 50000)),
                StreetAddress1 = "This record was inserted via a test",
                City = "Fictional city",
                State = "LA",
                ZipCode = "12345"
            };

            using (new UnitOfWorkScope())
            {
                var customerRepository = new EFRepository<Customer>();
                var recordCheckResult = (from cust in customerRepository
                                         where cust.FirstName == newCustomer.FirstName &&
                                               cust.LastName == newCustomer.LastName
                                         select cust).FirstOrDefault();
                Assert.That(recordCheckResult, Is.Null);

                customerRepository.Add(newCustomer);
                //DO NOT CALL COMMIT TO SIMMULATE A ROLLBACK.
            }

            //Starting a completely new unit of work and repository to check for existance.
            using (var scope = new UnitOfWorkScope())
            {
                var customerRepository = new EFRepository<Customer>();
                var recordCheckResult = (from cust in customerRepository
                                         where cust.FirstName == newCustomer.FirstName &&
                                               cust.LastName == newCustomer.LastName
                                         select cust).FirstOrDefault();
                Assert.That(recordCheckResult, Is.Null);
                scope.Commit();
            }
        }
        public void GetAllNews_ShouldReturnAllNews()
        {
            // Arange
            this.CleanUpDatabase();
            var listWithNews = new List<News>();
            var repo = new EFRepository<News>(this.dbcontext);
            var new1 = new News() { Content = "Content 1", Title = "Title 1", PublishedAt = DateTime.Now };
            var new2 = new News() { Content = "Content 2", Title = "Title 2", PublishedAt = DateTime.Now };

            // Act
            repo.Add(new1);
            repo.Add(new2);
            repo.SaveChanges();

            listWithNews.Add(new1);
            listWithNews.Add(new2);

            // Assert
            Assert.AreEqual(2, repo.All().Count());
            CollectionAssert.AreEquivalent(listWithNews, repo.All().ToList());
        }
Exemplo n.º 41
0
        public void Can_save()
        {
            var customer = new Customer
            {
                FirstName = "Jane",
                LastName = "Doe",
                StreetAddress1 = "123 Main St",
                City = "Sunset City",
                State = "LA",
                ZipCode = "12345"
            };

            using (var scope = new UnitOfWorkScope())
            {
                var repository = new EFRepository<Customer>();
                repository.Add(customer);
                scope.Commit();
            }
            Assert.That(customer.CustomerID, Is.GreaterThan(0));
            using (var testData = new EFTestData(OrdersContextProvider()))
            {
                Customer savedCustomer = null;
                testData.Batch(action => savedCustomer = action.GetCustomerById(customer.CustomerID));
                Assert.That(savedCustomer, Is.Not.Null);
                Assert.That(savedCustomer.CustomerID, Is.EqualTo(customer.CustomerID));
            }
        }