Esempio n. 1
0
        public void Should_UpdatePreferences()
        {
            var teams = CreateDataContext().AddTeams(5);

            foreach (var t in teams)
            {
                var prefRes = GetRepo <TeamRepository>()
                              .ForActiveOrg(t.OrgId)
                              .GetPreferences(t.Id);

                Assert.False(prefRes.HasError);

                var model      = prefRes.Value;
                var emptyModel = new ModelTeamPreferences()
                {
                    TeamId = t.Id, OrgId = t.OrgId
                };
                Assert.True(emptyModel.Equals(prefRes.Value));

                TestFactory.Update(model);

                Assert.False(GetRepo <TeamRepository>()
                             .ForActiveOrg(t.OrgId)
                             .UpdatePreferences(model)
                             .HasError);

                prefRes = GetRepo <TeamRepository>()
                          .ForActiveOrg(t.OrgId)
                          .GetPreferences(t.Id);

                Assert.False(prefRes.HasError);

                Assert.True(model.Equals(prefRes.Value));
            }
        }
Esempio n. 2
0
        public void Should_DeleteTeamsAndPreferences()
        {
            var teams = CreateDataContext().AddTeams(5);

            CreateDataContext().AddTeamPreferences();

            Assert.True(CreateDataContext()
                        .Preferences
                        .ToList()
                        .Count == teams.Count);

            foreach (var t in teams)
            {
                Assert.False(GetRepo <TeamRepository>()
                             .ForActiveOrg(t.OrgId)
                             .Delete(t.Id)
                             .HasError);

                var prefCount = CreateDataContext()
                                .Preferences
                                .ToList()
                                .Count;

                var teamCount = CreateDataContext()
                                .Teams
                                .ToList()
                                .Count;

                Assert.True(prefCount == teamCount);

                var model = GetRepo <TeamRepository>()
                            .ForActiveOrg(t.OrgId)
                            .GetPreferences(t.Id);

                Assert.False(model.HasError);

                var emptyModel = new ModelTeamPreferences()
                {
                    OrgId = t.OrgId, TeamId = t.Id
                };
                Assert.True(emptyModel.Equals(model.Value));
            }

            Assert.Empty(CreateDataContext()
                         .Preferences
                         .ToList());
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="teamId"></param>
        /// <returns></returns>
        public OperationResult <ModelPreferences> UpdatePreferences(ModelPreferences pref)
        {
            OperationResult <ModelPreferences> res;

            try
            {
                var entity = DataContext
                             .Teams
                             .ForActiveOrg()
                             .Include(x => x.Preferences)
                             .FirstOrDefault(x => x.Id == pref.TeamId);

                if (null == entity)
                {
                    return(OperationResult <ModelPreferences> .Create(ErrorCode.BadGetTeam));
                }

                if (null != entity.Preferences)
                {
                    entity.Preferences.Update(pref);
                }
                else
                {
                    entity.Preferences = pref.ToTeamEntity();
                }

                DataContext.SaveChanges();

                var model = entity
                            .Preferences
                            .UpdateId(pref)
                            .ToTeamModel();

                res = OperationResult <ModelPreferences> .Create(model);
            }
            catch (Exception e)
            {
                res = OperationResult <ModelPreferences> .Create(ErrorCode.BadUpdateTeamPreferences, e);
            }

            return(res);
        }
Esempio n. 4
0
        public void ShouldNot_UpdatePreferencesWhenBadTeamId()
        {
            var teams = CreateDataContext().AddTeams(5);

            foreach (var t in teams)
            {
                var prefRes = GetRepo <TeamRepository>()
                              .ForActiveOrg(t.OrgId)
                              .GetPreferences(t.Id);

                Assert.False(prefRes.HasError);

                var model      = prefRes.Value;
                var emptyModel = new ModelTeamPreferences()
                {
                    TeamId = t.Id, OrgId = t.OrgId
                };
                Assert.True(emptyModel.Equals(prefRes.Value));

                TestFactory.Update(model);

                Assert.True(GetRepo <TeamRepository>()
                            .ForActiveOrg(0)
                            .UpdatePreferences(model)
                            .Error
                            .Code == ErrorCode.BadGetTeam);

                model.TeamId = TestFactory.GetRandomUShort(1000) + 1000;

                Assert.True(GetRepo <TeamRepository>()
                            .ForActiveOrg(t.OrgId)
                            .UpdatePreferences(model)
                            .Error
                            .Code == ErrorCode.BadGetTeam);
            }
        }