public async Task SuccessToAddLogIfMandatoryFieldsAreFilled()
        {
            await _logRepoMock.InsertLog(Arg.Any <UserLog>());

            await _logService.AddLog(TimeSpan.FromMinutes(10), UserActionTypes.GetAnagrams, "oskaras");

            await _logRepoMock.Received().InsertLog(Arg.Any <UserLog>());
        }
        public void GenerateUserLogReport_ShouldGenerateCorrectUserLogReport()
        {
            userLogRepository.GetUserLogReport().Returns(new List <UserLogReport>
            {
                new UserLogReport {
                    UserIp = "107.0.0.1", SearchTime = new DateTime(2019, 7, 19), Word = "dangus", Anagrams = new List <string> {
                        "dugnas"
                    }
                },
                new UserLogReport {
                    UserIp = "107.0.0.1", SearchTime = new DateTime(2019, 7, 19), Word = "dangus", Anagrams = new List <string> {
                        "gandus"
                    }
                }
            });

            List <string> expected = new List <string> {
                "dugnas", "gandus"
            };

            var result = userLogService.GenerateUserLogReport();

            Assert.IsNotNull(result);
            Assert.AreEqual(expected, result.First().Anagrams);

            userLogRepository.Received().GetUserLogReport();
        }
        public void GetAllLogs_ShouldGetAllIpAddresses()
        {
            _userLogRepository.GetUserLogs().Returns(new List <UserLogFull> {
                new UserLogFull("1", new DateTime(), 1),
                new UserLogFull("2", new DateTime(), 2)
            });

            var result = _userLogService.GetAllLogs();

            result.ShouldNotBeNull();
            result.Select(a => a.IP_address).ToList().ShouldBe(new List <string> {
                "1", "2"
            });

            _userLogRepository.Received().GetUserLogs();
        }
        public void GetAnagrams_ShouldReturnExistingAnagrams()
        {
            string word = "dangus";
            string ip   = "107.0.0.1";

            allowedSearchesRepository.CheckIfExists(ip).Returns(true);
            allowedSearchesRepository.GetAmountOfSearches(ip).Returns(10);
            userLogRepository.CountUserSearchesByIp(ip).Returns(1);
            cacheRepository.GetCachedAnagrams(word).Returns(new List <string> {
                "dugnas", "gandus"
            });

            var result = anagramService.GetAnagrams(word, ip);

            Assert.IsNotNull(result);
            Assert.AreEqual("dugnas", result.First());

            allowedSearchesRepository.Received().CheckIfExists(ip);
            allowedSearchesRepository.Received().GetAmountOfSearches(ip);
            userLogRepository.Received().CountUserSearchesByIp(ip);
            cacheRepository.Received().GetCachedAnagrams(word);

            allowedSearchesRepository.DidNotReceive().SaveNewUser(Arg.Any <string>(), Arg.Any <int>());
            wordRepository.DidNotReceive().FindAnagrams(Arg.Any <string>());
            cacheRepository.DidNotReceive().Save(Arg.Any <string>(), Arg.Any <IEnumerable <string> >());
        }
Example #5
0
        public void GetUserLogListByIp_ShouldReturnUserLogListByIp()
        {
            ipAddress = "::1";

            UserLogModel expected = new UserLogModel()
            {
                RequestedWord = "labas",
                UserIp        = "::1",
            };

            var sample = new UserLogEntity()
            {
                Id   = 1,
                User = new UserEntity()
                {
                    Id = 1, Ip = "::1"
                },
                Request = new RequestEntity()
                {
                    Id = 1, Word = "labas"
                },
                Date = DateTime.Now
            };


            _userLogRepository.GetUserLogListByIp(ipAddress).Returns(new List <UserLogEntity>
            {
                sample,
                new UserLogEntity()
                {
                    Id   = 2,
                    User = new UserEntity()
                    {
                        Id = 1, Ip = "::1"
                    },
                    Request = new RequestEntity()
                    {
                        Id = 2, Word = "Labas"
                    },
                    Date = DateTime.Now
                },
                new UserLogEntity()
                {
                    Id   = 3,
                    User = new UserEntity()
                    {
                        Id = 2, Ip = "::2"
                    },
                    Request = new RequestEntity()
                    {
                        Id = 2, Word = "Labas"
                    },
                    Date = DateTime.Now
                },
            });

            //////////////////////////////////
            //////////////////////////////////


            var result = _userService.GetUserLogListByIp(ipAddress);


            result.ShouldNotBeNull();

            sample.User.Ip.ShouldBeSameAs(expected.UserIp);
/*            sample.Request.Id.ShouldBeSameAs()*/


            _userLogRepository.Received().GetUserLogListByIp(ipAddress);
        }