public void GetAllTapesTest_ReturnsListOfTwoTapeDTO() { // act var result = service.GetAllTapes(""); // assert Assert.IsInstanceOfType(result, typeof(IEnumerable <TapeDTO>)); Assert.AreEqual(2, result.Count()); _tapeRepository.Verify((m => m.GetAllTapes()), Times.Once()); }
public IActionResult GetAllTapes([FromQuery] DateTime?loanDate = null) { if (loanDate != null) { return(Ok(_tapeService.GetLoanReportForTapes((DateTime)loanDate))); } return(Ok(_tapeService.GetAllTapes())); }
public IActionResult GetAllTapes([FromQuery] string LoanDate) { // If no loan date provided as query parameter all tapes are returned if (String.IsNullOrEmpty(LoanDate)) { return(Ok(_tapeService.GetAllTapes())); } // Otherwise return record of all tape borrows on date specified // If loan date is an invalid date, throw 400 parameter format exception else { DateTime BorrowDate; if (!DateTime.TryParse(LoanDate, out BorrowDate)) { throw new ParameterFormatException("LoanDate"); } return(Ok(_tapeService.GetTapeReportAtDate(BorrowDate))); } }
//Returns random movie the user hasn't seen public TapeDetailDTO GetRecommendation(int userId) { var user = _userService.GetUserById(userId); var tapes = _tapeService.GetAllTapes(""); var reviews = _reviewService.GetAllReviewsForAllTapes(); var userBorrowedTapeIds = user.BorrowHistory.Select(u => u.TapeId).ToArray(); var unseenTapes = tapes.Where(t => !userBorrowedTapeIds.Contains(t.Id)).ToList(); // var reviewedTapeIds = reviews.OrderByDescending(r => r.Score).Select(r => r.TapeId).ToArray(); // var reviewedTapes = unseenTapes.Where(t => reviewedTapeIds.Contains(t.Id)).ToList(); // Getting random movie that user hasn't seen Random rnd = new Random(); int randomIndex = rnd.Next(0, unseenTapes.Count() - 1); var tapeId = unseenTapes.Select(t => t.Id).ElementAt(randomIndex); return(_tapeService.GetTapeById(tapeId)); }
public IActionResult InitializeUsersAndBorrows() { // We do not initialize unless database is empty for safety reasons if (_userService.GetAllUsers().Count > 0) { return(BadRequest(new ExceptionModel { StatusCode = (int)HttpStatusCode.BadRequest, Message = "Users have already been initialized in some form" })); } // We do not initialize users unless tapes have been initialized due to borrow records if (_tapeService.GetAllTapes().Count == 0) { return(BadRequest(new ExceptionModel { StatusCode = (int)HttpStatusCode.BadRequest, Message = "Tapes need to be initialized before users. Call [POST] /tapes/initialize before." })); } // Otherwise add users from initialization file using (StreamReader r = StreamReaderFactory.GetStreamReader("../Resources/usersAndBorrows.json")) { string json = r.ReadToEnd(); dynamic usersJSON = JsonConvert.DeserializeObject(json); foreach (var userJSON in usersJSON) { // Generate input model from json for user UserInputModel user = SeedingUtils.ConvertJsonToUserInputModel(userJSON); // Check if tape input model is valid if (!ModelState.IsValid) { IEnumerable <string> errorList = ModelState.Values.SelectMany(v => v.Errors).Select(x => x.ErrorMessage); throw new InputFormatException("User in initialization file improperly formatted.", errorList); } // Create new user if input model was valid Console.WriteLine($"adding user and user records for user {userJSON.id} of {usersJSON.Count}"); int userId = _userService.CreateUser(user); SeedingUtils.CreateTapesForUser(userJSON, _tapeService); } } return(NoContent()); }
public void GetAllTapes_TestingLength() { // arrange _tapeRepositoryMock.Setup(method => method.GetAllTapes()).Returns( FizzWare.NBuilder.Builder <TapeDto> .CreateListOfSize(2) .TheFirst(1).With(x => x.Id = 1).With(x => x.Eidr = "1").With(x => x.Title = "Pulp Fiction") .With(x => x.Type = "VHS").With(x => x.AverageRating = 2.2) .With(x => x.DirectorName = "Quentin Tarantino") .With(x => x.ReleaseDate = DateTime.Today) .TheNext(1).With(x => x.Id = 2).With(x => x.Eidr = "2").With(x => x.Title = "Brain Dead") .With(x => x.Type = "VHS").With(x => x.AverageRating = 9.9) .With(x => x.DirectorName = "Peter Jackson") .With(x => x.ReleaseDate = DateTime.Now) .Build()); // act var tapes = _tapeService.GetAllTapes(); // assert Assert.AreEqual(2, tapes.Count()); Assert.AreNotEqual(100, tapes.Count()); Assert.IsNotNull(tapes); }
public IActionResult GetAllTapes([FromQuery] string LoanDate = "") { return(Ok(_tapeService.GetAllTapes(LoanDate))); }
public void GetAllTapes_ReturnsListOfAllTapes() { var tapes = _tapeService.GetAllTapes(); Assert.AreEqual(_tapeMockListSize, tapes.Count()); }