public ActionResult PaymentProcess(double penalty, string bookName, BookViewModel bookVm) { BookOperation book = (from p in Process.BookOperations where p.BookName == bookName select p).FirstOrDefault(); bookVm.CategoryName = book.CategoryName; bookVm.BookName = book.BookName; bookVm.AuthorName = book.AuthorName; bookVm.PublisherName = book.PublisherName; bookVm.ReceivingDate = book.ReceivingDate; bookVm.GivingDate = book.GivingDate; bookVm.PenaltyQuantity = penalty; var Penalties = (from p in Process.Penalties where p.PenaltyQuantity == penalty select p).FirstOrDefault(); var bo = (from b in Process.BookOperations where b.Id == Penalties.BookOperationId && b.BookName == bookName select b).FirstOrDefault(); var selectedpenalty = (from sp in Process.Penalties where sp.BookOperationId == bo.Id select sp).FirstOrDefault(); selectedpenalty.PenaltyQuantity = 0; Process.SaveChanges(); TempData["notice"] = "Ödeme işleminiz gerçekleşmiştir"; return(View(bookVm)); }
public void BookReceive(string bookName, BookViewModel bookVm, string session) { BookView bookV = (from p in bookDC.BookViews where p.BookName == bookName select p).FirstOrDefault(); Book book = (from p in bookDC.Books where p.BookName == bookName select p).FirstOrDefault(); bookVm.CategoryName = bookV.CategoryName; bookVm.BookName = bookV.BookName; bookVm.AuthorName = bookV.AuthorName; bookVm.PublisherName = bookV.PublisherName; book.BookQuantity--; BookOperation BO = new BookOperation(); Penalty penalty = new Penalty(); BO.UserName = session; BO.ReceivingDate = DateTime.Now; BO.CategoryName = bookVm.CategoryName; BO.BookName = bookVm.BookName; BO.AuthorName = bookVm.AuthorName; BO.PublisherName = bookVm.PublisherName; bookDC.BookOperations.Add(BO); bookDC.SaveChanges(); penalty.BookOperationId = BO.Id; penalty.PenaltyQuantity = 0; bookDC.Penalties.Add(penalty); bookDC.SaveChanges(); }
public void EditTable(Book book) { BookOperation EditBook = new BookOperation( tableAndFileControll, CommandType.EditCommand); EditBook.SetCommand(book); }
public void AddTable(Book book) { BookOperation addBook = new BookOperation( tableAndFileControll, CommandType.AddCommand ); addBook.SetCommand(book); }
public void CreateBook_BookName_Empty() { Mock <IFileOperation> mockFile = new Mock <IFileOperation>(); BookOperation bookOperation = new BookOperation(mockFile.Object); BookResult result = bookOperation.CreateBook(new Book { userName = "******", bookName = "" }); Assert.Equal("Empty BookName", result.message); }
public void writeCommentToFile_Success() { Mock <IFileOperation> mockFile = new Mock <IFileOperation>(); mockFile.Setup(x => x.WriteCommentToFile(It.IsAny <Domain.Book>(), It.IsAny <string>())).Returns(new BookResult { isSuccess = true, message = "success" }); BookOperation bookOperation = new BookOperation(mockFile.Object); Book book = new Book(); BookResult result = bookOperation.WriteCommentToFile(book, "testComment"); Assert.True(result.isSuccess); }
public void readControl_Success() { Mock <IFileOperation> mockFile = new Mock <IFileOperation>(); mockFile.Setup(x => x.readControl(It.IsAny <Domain.User>(), It.IsAny <Domain.Book>())).Returns(new BookResult { isSuccess = true, message = "success" }); BookOperation bookOperation = new BookOperation(mockFile.Object); Book book = new Book(); User user = new User(); BookResult result = bookOperation.readControl(user, book); Assert.True(result.isSuccess); }
public void incrementLikeCount_Success() { Mock <IFileOperation> mockFile = new Mock <IFileOperation>(); mockFile.Setup(x => x.ReadTheBookFromFileChangeTheLikeCount(It.IsAny <Domain.Book>(), It.IsAny <Domain.User>())).Returns(new BookResult { isSuccess = true, message = "success" }); BookOperation bookOperation = new BookOperation(mockFile.Object); Book book = new Book(); User user = new User(); BookResult result = bookOperation.incrementLikeCount(book, user); Assert.True(result.isSuccess); }
public void BookManager_Rent_ReduceStock() { //Mockeo las dependencias que no quiero testear var bookRepository = new Mock <IBookRepository>(); var bookOperationRepository = new Mock <IBookOperationRepository>(); var httpContextAccesor = new Mock <IHttpContextAccessor>(); var userManager = new Mock <UserManager <ApplicationUser> >( new Mock <IUserStore <ApplicationUser> >().Object, new Mock <IOptions <IdentityOptions> >().Object, new Mock <IPasswordHasher <ApplicationUser> >().Object, new IUserValidator <ApplicationUser> [0], new IPasswordValidator <ApplicationUser> [0], new Mock <ILookupNormalizer>().Object, new Mock <IdentityErrorDescriber>().Object, new Mock <IServiceProvider>().Object, new Mock <ILogger <UserManager <ApplicationUser> > >().Object); //Creo los objetos dummy a utilizar en los tests var book = new Book() { Id = new Guid(), Name = "TestBook", Stock = 10, BookClients = new List <BookClient>() }; var user = new ApplicationUser() { Id = new Guid(), Email = "*****@*****.**" }; var bookOperation = new BookOperation() { Book = book, Date = DateTime.Now, Type = Enums.BookOperations.Rent, User = user }; var claim = new ClaimsPrincipal(); //Hago un setup para indicarle a los metodos de las clases mockeadas que no quiero testear, lo que deben devolver bookRepository.Setup(x => x.GetById(new Guid())).ReturnsAsync(book); bookRepository.Setup(x => x.Update(book, new Guid())).Returns(Task.FromResult(book)); httpContextAccesor.Setup(x => x.HttpContext.User).Returns(claim); userManager.Setup(x => x.GetUserAsync(claim)).ReturnsAsync(user); bookOperationRepository.Setup(x => x.Insert(bookOperation)).Returns(Task.FromResult(bookOperation)); //Instancio la clase a testear var bookManager = new BookManager(bookRepository.Object, bookOperationRepository.Object, userManager.Object, httpContextAccesor.Object); //Ejecuto el metodo a testear var result = bookManager.Rent(book.Id).Result; //Hago el Assert para chequear que haya llegado bien Assert.Equal(9, result); //TODO: ver si puedo hacer inyeccion de dependencias en xUnit. Mover la creacion de los objetos dummy a un fixture }
public void CreateBook_Success() { Mock <IFileOperation> mockFile = new Mock <IFileOperation>(); mockFile.Setup(x => x.WriteTheBookToTheFile(It.IsAny <Domain.Book>())).Returns(new Domain.FileResult { isSuccess = true }); BookOperation bookOperation = new BookOperation(mockFile.Object); BookResult result = bookOperation.CreateBook(new Book { userName = "******", bookName = "enesbayar", likeCount = 0, comment = "test" }); Assert.True(result.isSuccess); }
public ActionResult Payment(double penalty, string bookName, BookViewModel bookVm) { BookOperation book = (from p in Process.BookOperations where p.BookName == bookName select p).FirstOrDefault(); bookVm.CategoryName = book.CategoryName; bookVm.BookName = book.BookName; bookVm.AuthorName = book.AuthorName; bookVm.PublisherName = book.PublisherName; bookVm.ReceivingDate = book.ReceivingDate; bookVm.GivingDate = book.GivingDate; bookVm.PenaltyQuantity = penalty; return(View(bookVm)); }
public ActionResult GivingProcess(double penalty, string bookName, BookViewModel bookVm) { BookOperation book = (from p in Process.BookOperations where p.BookName == bookName select p).FirstOrDefault(); bookVm.CategoryName = book.CategoryName; bookVm.BookName = book.BookName; bookVm.AuthorName = book.AuthorName; bookVm.PublisherName = book.PublisherName; bookVm.ReceivingDate = book.ReceivingDate; bookVm.GivingDate = book.GivingDate; bookVm.PenaltyQuantity = penalty; var penlty = (from p in Process.Penalties where p.PenaltyQuantity == penalty select p).ToList(); string session = Session["UserID"].ToString(); BookOperation bkO = null; foreach (var item in penlty) { bkO = (from bko in Process.BookOperations where bko.UserName == session && bko.Id == item.BookOperationId && bko.BookName == bookName && bko.ReceivingDate != null && bko.GivingDate == null select bko).FirstOrDefault(); if (bkO != null) { break; } } var bk = (from b in Process.Books where b.BookName == bookName select b).FirstOrDefault(); bk.BookQuantity++; bkO.GivingDate = DateTime.Now; Process.SaveChanges(); TempData["notice"] = "Kitabı verme işleminiz başarılı"; return(View(bookVm)); }
public void ReadBook_Success() { Mock <IFileOperation> mockFile = new Mock <IFileOperation>(); mockFile.Setup(x => x.ReadTheBookFromFile()).Returns(new ArrayList { new Book { userName = "******", bookName = "testALBookName", likeCount = 0, comment = "testALComment" }, new Book { userName = "******", bookName = "testALBookName2", likeCount = 0, comment = "testALComment2" } }); BookOperation bookOperation = new BookOperation(mockFile.Object); ArrayList arrayListResult = bookOperation.ReadBook(); Assert.NotNull(arrayListResult); }
private async Task InsertBookOperationLog(ApplicationUser currentUser, Book book, BookOperations bookOperationType) { var bookOperation = new BookOperation(currentUser, book, bookOperationType); await _bookOperationRepository.Insert(bookOperation); }
public void BookGive(BookViewModel bookVm, string session) { TimeSpan?interval; DateTime?receivingDate, givingDate; receivingDate = null; interval = null; BookOperation bkO = null; if (bookVm.PublisherName == null) { bkO = (from bo in bookDC.BookOperations where bo.UserName == session && bo.BookName == bookVm.BookName && bo.ReceivingDate != null select bo).FirstOrDefault(); } else { bkO = (from bo in bookDC.BookOperations where bo.UserName == session && bo.BookName == bookVm.BookName select bo).FirstOrDefault(); } var authr = (from a in bookDC.Authors where a.AuthorName == bookVm.AuthorName select a).FirstOrDefault(); Penalty penalty = new Penalty(); BookOperation BO = new BookOperation(); if (bkO == null) { BO.UserName = session; BO.CategoryName = bookVm.CategoryName; BO.BookName = bookVm.BookName; BO.PublisherName = bookVm.PublisherName; BO.GivingDate = DateTime.Now; if (!string.IsNullOrEmpty(bookVm.AuthorName)) { BO.AuthorName = bookVm.AuthorName; } else { BO.AuthorName = "-"; } bookDC.BookOperations.Add(BO); bookDC.SaveChanges(); penalty.BookOperationId = BO.Id; penalty.PenaltyQuantity = 0; bookDC.Penalties.Add(penalty); } else { if (bkO.ReceivingDate == null) { BO.UserName = session; BO.CategoryName = bookVm.CategoryName; BO.BookName = bookVm.BookName; BO.PublisherName = bookVm.PublisherName; BO.GivingDate = DateTime.Now; BO.ReceivingDate = null; if (!string.IsNullOrEmpty(bookVm.AuthorName)) { BO.AuthorName = bookVm.AuthorName; } else { BO.AuthorName = "-"; } bookDC.BookOperations.Add(BO); bookDC.SaveChanges(); penalty.BookOperationId = BO.Id; penalty.PenaltyQuantity = 0; bookDC.Penalties.Add(penalty); } else { receivingDate = bkO.ReceivingDate; bkO.GivingDate = DateTime.Now; givingDate = bkO.GivingDate; interval = givingDate - receivingDate; foreach (var item in bookDC.Penalties) { if (item.BookOperationId == bkO.Id) { if (interval.Value.Days <= 7) { item.PenaltyQuantity = 0; } else { item.PenaltyQuantity = (double)interval.Value.Days * 0.50; break; } } } } var bk = (from b in bookDC.Books where b.BookName == bookVm.BookName select b).FirstOrDefault(); Book book = new Book(); if (bk == null) { book.BookName = bookVm.BookName; book.CategoryId = (from item in bookDC.Categories where item.CategoryName == bookVm.CategoryName select item.CategoryId).FirstOrDefault(); book.BookQuantity = 1; bookDC.Books.Add(book); } else { bk.BookQuantity++; } Author author = new Author(); if (authr == null) { if (bookVm.AuthorName != null) { author.AuthorName = bookVm.AuthorName; bookDC.Authors.Add(author); Book_Author BA = new Book_Author(); BA.AuthorId = author.AuthorId; BA.BookId = book.BookId; bookDC.Book_Author.Add(BA); } else { if (bkO.GivingDate != null) { } else { author.AuthorName = "-"; bookDC.Authors.Add(author); Book_Author BA = new Book_Author(); BA.AuthorId = author.AuthorId; BA.BookId = book.BookId; bookDC.Book_Author.Add(BA); } } } var publishr = (from p in bookDC.Publishers where p.PublisherName == bookVm.PublisherName select p).FirstOrDefault(); Publisher publshr = new Publisher(); if (publishr == null) { if (bookVm.PublisherName != null) { publshr.PublisherName = bookVm.PublisherName; bookDC.Publishers.Add(publshr); Book_Publisher BP = new Book_Publisher(); BP.PublisherId = publshr.PublisherId; BP.BookId = book.BookId; bookDC.Book_Publisher.Add(BP); } else { if (bkO.GivingDate != null) { } else { publshr.PublisherName = "-"; bookDC.Publishers.Add(publshr); Book_Publisher BP = new Book_Publisher(); BP.PublisherId = publshr.PublisherId; BP.BookId = book.BookId; bookDC.Book_Publisher.Add(BP); } } } bookDC.SaveChanges(); } }
public BookSaveCommand(BookViewModel book, BookOperation operation) { BookOperation = operation; BookOperation.Target.Name = book.Name; }
public BooksController() { eventBroker = new EventBroker(); bookOperation = new BookOperation(eventBroker); }