コード例 #1
0
        public static Option CreateOption()
        {
            Option option = new Option("This is a headline", "Here is some option");

            EntityIdSetter.SetIdOf(option, 1);
            return(option);
        }
コード例 #2
0
        public static Cup CreateCup(int id)
        {
            Cup cup = new Cup("Cup Name");

            EntityIdSetter.SetIdOf(cup, id);
            return(cup);
        }
コード例 #3
0
        public static Task CreateTask()
        {
            Task task = CreateTransientTask();

            EntityIdSetter.SetIdOf <int>(task, 1);
            return(task);
        }
コード例 #4
0
        private static Game CreateGame()
        {
            Game game = CreateTransientGame();

            EntityIdSetter.SetIdOf <int>(game, 1);
            return(game);
        }
コード例 #5
0
        private BonusTask CreateBonusTask()
        {
            BonusTask bonusTask = CreateTransientBonusTask();

            EntityIdSetter.SetIdOf <int>(bonusTask, 1);
            return(bonusTask);
        }
コード例 #6
0
        public void CanBeUsedByLinqSetOperatorsSuchAsIntersect()
        {
            IList <ConcreteEntityWithDomainSignatureProperties> objects1 = new List <ConcreteEntityWithDomainSignatureProperties>();
            ConcreteEntityWithDomainSignatureProperties         object1  = new ConcreteEntityWithDomainSignatureProperties()
            {
                Name = "Billy McCafferty",
            };

            EntityIdSetter.SetIdOf <int>(object1, 2);
            objects1.Add(object1);

            IList <ConcreteEntityWithDomainSignatureProperties> objects2 = new List <ConcreteEntityWithDomainSignatureProperties>();
            ConcreteEntityWithDomainSignatureProperties         object2  = new ConcreteEntityWithDomainSignatureProperties()
            {
                Name = "Jimi Hendrix",
            };

            EntityIdSetter.SetIdOf <int>(object2, 1);
            objects2.Add(object2);
            ConcreteEntityWithDomainSignatureProperties object3 = new ConcreteEntityWithDomainSignatureProperties()
            {
                Name = "Doesn't Matter since the Id will match and the presedence of the domain signature will go overridden",
            };

            EntityIdSetter.SetIdOf <int>(object3, 2);
            objects2.Add(object3);

            Assert.That(objects1.Intersect(objects2,
                                           new BaseObjectEqualityComparer <ConcreteEntityWithDomainSignatureProperties>()).Count(),
                        Is.EqualTo(1));
            Assert.AreEqual(objects1.Intersect(objects2,
                                               new BaseObjectEqualityComparer <ConcreteEntityWithDomainSignatureProperties>()).First(), object1);
            Assert.AreEqual(objects1.Intersect(objects2,
                                               new BaseObjectEqualityComparer <ConcreteEntityWithDomainSignatureProperties>()).First(), object3);
        }
コード例 #7
0
        public static Event CreateEvent()
        {
            Event evt = new Event("Title", "Desc", DateTime.Now);

            EntityIdSetter.SetIdOf(evt, 1);
            return(evt);
        }
コード例 #8
0
        private static Employee CreateEmployee()
        {
            Employee employee = CreateTransientEmployee();

            EntityIdSetter.SetIdOf <int>(employee, 1);
            return(employee);
        }
コード例 #9
0
        public void CanCompareEntities()
        {
            var object1 = new ObjectWithIntId {
                Name = "Acme"
            };
            var object2 = new ObjectWithIntId {
                Name = "Anvil"
            };

            Assert.That(object1, Is.Not.EqualTo(null));
            Assert.That(object1, Is.Not.EqualTo(object2));

            EntityIdSetter.SetIdOf(object1, 10);
            EntityIdSetter.SetIdOf(object2, 10);

            // Even though the "business value signatures" are different, the persistent Ids
            // were the same.  Call me crazy, but I put that much trust into persisted Ids.
            Assert.That(object1, Is.EqualTo(object2));
            Assert.That(object1.GetHashCode(), Is.EqualTo(object2.GetHashCode()));

            var object3 = new ObjectWithIntId {
                Name = "Acme"
            };

            // Since object1 has an Id but object3 doesn't, they won't be equal
            // even though their signatures are the same
            Assert.That(object1, Is.Not.EqualTo(object3));

            var object4 = new ObjectWithIntId {
                Name = "Acme"
            };

            // object3 and object4 are both transient and share the same signature
            Assert.That(object3, Is.EqualTo(object4));
        }
コード例 #10
0
ファイル: UserTest.cs プロジェクト: ucdavis/Recruitments
        public override void LoadData()
        {
            base.LoadData();

            Login login = new Login();

            EntityIdSetter.SetIdOf <string>(login, StaticProperties.TestString);

            //Load in a user
            User user = new User();

            user.FirstName = StaticProperties.TestString;
            user.LastName  = StaticProperties.TestString;
            user.LoginIDs  = new List <Login> {
                login
            };

            login.User = user;

            using (var ts = new TransactionScope())
            {
                UserBLL.EnsurePersistent(user);
                GenericBLL <Login, string> .EnsurePersistent(login, true);

                ts.CommitTransaction();
            }
        }
コード例 #11
0
        private static Code CreateCode()
        {
            Code code = CreateTransientCode();

            EntityIdSetter.SetIdOf <int>(code, 1);
            return(code);
        }
コード例 #12
0
        public void CanCompareEntities()
        {
            var obj1 = new ObjectWithIntId {
                Name = "Acme"
            };
            var obj2 = new ObjectWithIntId {
                Name = "Anvil"
            };

            obj1.Equals(null).Should().BeFalse();
            obj1 !.Equals(obj2).Should().BeFalse();

            EntityIdSetter.SetIdOf(obj1, 10);
            EntityIdSetter.SetIdOf(obj2, 10);

            // Even though the "business value signatures" are different, the persistent Ids
            // were the same.  Call me crazy, but I put that much trust into persisted Ids.
            obj1.Equals(obj2).Should().BeTrue();
            obj1.GetHashCode().Should().Be(obj2.GetHashCode());

            var obj3 = new ObjectWithIntId {
                Name = "Acme"
            };

            // Since obj1 has an Id but obj3 doesn't, they won't be equal
            // even though their signatures are the same
            obj1.Equals(obj3).Should().BeFalse();

            var obj4 = new ObjectWithIntId {
                Name = "Acme"
            };

            // obj3 and obj4 are both transient and share the same signature
            obj3.Equals(obj4).Should().BeTrue();
        }
コード例 #13
0
        public static IList <TeamLeague> CreateTeamLeagueList()
        {
            IList <TeamLeague> list = new List <TeamLeague>();

            League league = new League(new Season(2008, 2009), "Mens", 1, 1);

            EntityIdSetter.SetIdOf(league, 1);
            Team team = new Team("Velocity", "Velocity");

            EntityIdSetter.SetIdOf(team, 1);
            Team team2 = new Team("Heat", "Heat");

            EntityIdSetter.SetIdOf(team2, 2);

            TeamLeague teamLeague = new TeamLeague(league, team, "Velocity", "Velocity");

            EntityIdSetter.SetIdOf(teamLeague, 1);

            TeamLeague teamLeague2 = new TeamLeague(league, team2, "Velocity", "Velocity");

            EntityIdSetter.SetIdOf(teamLeague2, 2);

            list.Add(teamLeague);
            list.Add(teamLeague2);

            return(list);
        }
コード例 #14
0
        public static Tip CreateTip()
        {
            Tip tip = CreateTransientTip();

            EntityIdSetter.SetIdOf <int>(tip, 1);
            return(tip);
        }
コード例 #15
0
        private Team CreateTeam()
        {
            Team team = CreateTransientTeam();

            EntityIdSetter.SetIdOf <int>(team, 1);
            return(team);
        }
コード例 #16
0
        private Category CreateCategory()
        {
            Category category = new Category("Hawaiian");

            EntityIdSetter.SetIdOf(category, 1);
            return(category);
        }
コード例 #17
0
        public static IRepository <Role> CreateRoleRepository()
        {
            var roleRepositoryMock = MockRepository.GenerateStub <IRepository <Role> >();

            var roles = new List <Role>
            {
                new Role {
                    Name = "Administrator"
                },
                new Role {
                    Name = "Autor"
                },
                new Role {
                    Name = "Player"
                },
                new Role {
                    Name = "Guest"
                }
            };

            int id = 1;

            foreach (Role role in roles)
            {
                EntityIdSetter.SetIdOf <int>(role, id++);
            }

            roleRepositoryMock.Expect(r => r.GetAll()).Return(roles);

            return(roleRepositoryMock);
        }
コード例 #18
0
        public static PlayerCareerStats CreatePlayerCareerStats()
        {
            PlayerCareerStats p = new PlayerCareerStats(CreatePlayer(), 100, 20, 5, 1);

            EntityIdSetter.SetIdOf(p, 1);

            return(p);
        }
コード例 #19
0
        public static PlayerSeasonStats CreatePlayerSeasonStats(int id, Player player, Season season)
        {
            PlayerSeasonStats p = new PlayerSeasonStats(player, season, 100, 20, 5, 1);

            EntityIdSetter.SetIdOf(p, id);

            return(p);
        }
コード例 #20
0
 public void CanUpdateUser()
 {
     User userFromForm = CreateTransientUser();
     EntityIdSetter.SetIdOf(userFromForm, 1);
     controller.Edit(userFromForm)
         .AssertActionRedirect().ToAction("Index");
     controller.Message.ShouldContain("успешно сохранен");
 }
コード例 #21
0
        public static Player CreatePlayer()
        {
            Player player = new Player("Phil", "Hale", CreateTeam());

            EntityIdSetter.SetIdOf(player, 1);

            return(player);
        }
コード例 #22
0
        public static Season CreateSeason()
        {
            Season season = new Season(2008, 2009);

            EntityIdSetter.SetIdOf(season, 1);

            return(season);
        }
コード例 #23
0
        public void CanEnsureUserEditionIsValid()
        {
            User userFromForm = new User { Login = String.Empty, Password = String.Empty };
            EntityIdSetter.SetIdOf(userFromForm, 1);
            ViewResult result = controller.Edit(userFromForm).AssertViewRendered();

            result.ViewData.Model.ShouldNotBeNull();
            result.ViewData.Model.ShouldBeOfType(typeof(AdminUsersController.UserFormViewModel));
        }
コード例 #24
0
        public static User CreateUser()
        {
            User user = new User();

            user.Team = CreateTeam();

            EntityIdSetter.SetIdOf(user, 1);
            return(user);
        }
コード例 #25
0
        public void CanUpdateTeam()
        {
            Team teamFromForm = CreateTransientTeam();

            EntityIdSetter.SetIdOf <int>(teamFromForm, 1);
            RedirectToRouteResult redirectResult = controller.Edit(teamFromForm)
                                                   .AssertActionRedirect().ToAction("Index");

            controller.Message.ShouldContain("успешно изменена");
        }
コード例 #26
0
        public static TeamLeague CreateTeamLeague()
        {
            League league = new League(new Season(2008, 2009), "Mens", 1, 1);

            EntityIdSetter.SetIdOf(league, 1);
            Team       team       = new Team("Velocity", "Velocity");
            TeamLeague teamLeague = new TeamLeague(league, team, "Velocity", "Velocity");

            return(teamLeague);
        }
コード例 #27
0
        public void CannotEquateObjectsWithSameIdButDifferentTypes()
        {
            var object1Type = new Object1();
            var object2Type = new Object2();

            EntityIdSetter.SetIdOf(object1Type, 1);
            EntityIdSetter.SetIdOf(object2Type, 1);

            Assert.That(object1Type, Is.Not.EqualTo(object2Type));
        }
コード例 #28
0
        public void CannotEquateObjectsWithSameIdButDifferentTypes()
        {
            var obj1 = new Entity1();
            var obj2 = new Entity2();

            EntityIdSetter.SetIdOf(obj1, 1);
            EntityIdSetter.SetIdOf(obj2, 1);

            // ReSharper disable once SuspiciousTypeConversion.Global
            obj1.Equals(obj2).Should().BeFalse();
        }
コード例 #29
0
        public void CanUpdateBonusTask()
        {
            BonusTask bonusTaskFromForm = CreateTransientBonusTask();

            EntityIdSetter.SetIdOf <int>(bonusTaskFromForm, 1);
            RedirectToRouteResult redirectResult = controller.Edit(bonusTaskFromForm)
                                                   .AssertActionRedirect().ToAction("Edit");

            controller.TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()].ToString()
            .ShouldContain("успешно изменено");
        }
コード例 #30
0
        public void CanUpdateEmployee()
        {
            Employee employeeFromForm = MockEmployeeRepositoryFactory.CreateTransientEmployee();

            EntityIdSetter.SetIdOf <int>(employeeFromForm, 1);
            RedirectToRouteResult redirectResult = controller.Edit(employeeFromForm)
                                                   .AssertActionRedirect().ToAction("Index");

            controller.TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()].ToString()
            .ShouldContain("was successfully updated");
        }