Exemplo n.º 1
0
        private GifEntry AssignAvailablePropertiesToDomain(GifEntryDTOProperties gifEntryProperties)
        {
            GifEntry gifEntry = new GifEntry();

            gifEntry.Keyword = gifEntryProperties.Keyword;
            gifEntry.Url     = gifEntryProperties.Url;
            gifEntry.UserId  = gifEntryProperties.UserId;

            return(gifEntry);
        }
Exemplo n.º 2
0
 public static GifEntryDTO ConvertToDTO(this GifEntry g)
 {
     return(new GifEntryDTO
     {
         Id = g.Id,
         UserId = g.UserId,
         Url = g.Url,
         Keyword = g.Keyword,
         AlternateIndex = 1
     });
 }
Exemplo n.º 3
0
        private void ThrowExceptionIfGifEntryIsInvalid(GifEntry gifEntry)
        {
            IEnumerable <BusinessRule> brokenRules = gifEntry.GetBrokenRules();

            if (brokenRules.Count() > 0)
            {
                StringBuilder brokenRulesBuilder = new StringBuilder();
                brokenRulesBuilder.AppendLine("There were problems saving the GifAtMe GifEntry object:");
                foreach (BusinessRule businessRule in brokenRules)
                {
                    brokenRulesBuilder.AppendLine(businessRule.RuleDescription);
                }

                throw new Exception(brokenRulesBuilder.ToString());
            }
        }
Exemplo n.º 4
0
        public InsertGifEntryResponse InsertGifEntry(InsertGifEntryRequest insertGifEntryRequest)
        {
            GifEntry newGifEntry = AssignAvailablePropertiesToDomain(insertGifEntryRequest.GifEntryDTOProperties);

            try
            {
                ThrowExceptionIfGifEntryIsInvalid(newGifEntry);
                _gifEntryRepository.Insert(newGifEntry);
                return(new InsertGifEntryResponse());
            }
            catch (Exception ex)
            {
                return(new InsertGifEntryResponse()
                {
                    Exception = ex
                });
            }
        }
Exemplo n.º 5
0
 public static GifEntryDb ConvertToDatabase(this GifEntry gifEntry)
 {
     if (gifEntry != null)
     {
         GifEntryDb gifEntryDb = new GifEntryDb()
         {
             Id       = gifEntry.Id,
             UserDbId = gifEntry.UserId,
             Url      = gifEntry.Url,
             Keyword  = gifEntry.Keyword
         };
         return(gifEntryDb);
     }
     else
     {
         return(new GifEntryDb());
     }
 }
Exemplo n.º 6
0
 public static GifEntry ConvertToDomain(this GifEntryDb gifEntryDb)
 {
     if (gifEntryDb != null)
     {
         GifEntry gifEntry = new GifEntry()
         {
             Id      = gifEntryDb.Id,
             UserId  = gifEntryDb.UserDbId,
             Url     = gifEntryDb.Url,
             Keyword = gifEntryDb.Keyword
         };
         return(gifEntry);
     }
     else
     {
         return(new GifEntry());
     }
 }
Exemplo n.º 7
0
        public GetGifEntryResponse GetGifEntry(GetGifEntryRequest getGifEntryRequest)
        {
            GetGifEntryResponse getGifEntryResponse = new GetGifEntryResponse();
            GifEntry            gifEntry            = null;

            try
            {
                if (getGifEntryRequest.Id > 0)
                {
                    gifEntry = _gifEntryRepository.FindById(getGifEntryRequest.Id);
                }
                else
                {
                    if (getGifEntryRequest.UserIdSource.Equals(Constants.SlackIdSource))
                    {
                        // First get the user's application ID
                        var userId = _userRepository.GetAppUserIdBySlackUserId(getGifEntryRequest.UserId);

                        // Then request GifEntry repo to get the specified gif
                        gifEntry = _gifEntryRepository.GetGifEntryForUserIdAndKeywordAndAlternateIndex(userId, getGifEntryRequest.Keyword, getGifEntryRequest.AlternateIndex - 1);
                    }
                    else
                    {
                        gifEntry = _gifEntryRepository.GetGifEntryForUserIdAndKeywordAndAlternateIndex(getGifEntryRequest.UserId, getGifEntryRequest.Keyword, getGifEntryRequest.AlternateIndex - 1);
                    }
                }
                if (gifEntry == null)
                {
                    getGifEntryResponse.Exception = GetStandardGifEntryNotFoundException();
                }
                else
                {
                    getGifEntryResponse.GifEntry = gifEntry.ConvertToDTO();
                }
            }
            catch (Exception ex)
            {
                getGifEntryResponse.Exception = ex;
            }

            return(getGifEntryResponse);
        }
Exemplo n.º 8
0
        public void GenericRepo_FindByUserIdKeywordAndIndex_ObjectExistsInRepo()
        {
            // Setup
            var data = new List <GifEntry>
            {
                new GifEntry {
                    Id = 1, Keyword = "Test1", UserId = "12345"
                },
                new GifEntry {
                    Id = 2, Keyword = "Test2", UserId = "12345"
                },
                new GifEntry {
                    Id = 3, Keyword = "Test3", UserId = "12345"
                }
            }.AsQueryable();

            var mockSet = new Mock <DbSet <GifEntryDb> >();

            mockSet.As <IQueryable <GifEntry> >().Setup(m => m.Provider).Returns(data.Provider);
            mockSet.As <IQueryable <GifEntry> >().Setup(m => m.Expression).Returns(data.Expression);
            mockSet.As <IQueryable <GifEntry> >().Setup(m => m.ElementType).Returns(data.ElementType);
            mockSet.As <IQueryable <GifEntry> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());
            mockSet.Setup(m => m.AsNoTracking()).Returns(mockSet.Object);

            var mockContext = new Mock <GifAtMeContext>();

            mockContext.Setup(c => c.GifEntries).Returns(mockSet.Object);

            _mockDbContextFactory.Setup(x => x.Create()).Returns(mockContext.Object);

            var expectedModel = new GifEntry {
                Id = 1, Keyword = "Test1", UserId = "12345"
            };
            var sut = new GifEntryRepository(_mockUnitOfWork.Object, _mockDbContextFactory.Object);

            //Act
            var actualModel = sut.GetGifEntryForUserIdAndKeywordAndAlternateIndex("TestUser", "Test1", 0);

            //Assert
            Assert.AreEqual(expectedModel.Id, actualModel.Id);
        }