public async Task AddCommentAsync_ValidInput_AddsComment()
        {
            var lot = new Lot {
                SellerUserId = "*****@*****.**", StartDate = DateTime.Now, SellDate = DateTime.Now.AddDays(1), Name = "Name1"
            };
            await lotOperationsHandler.AddLotAsync(lot, "", "");

            var lotComment = new LotComment {
                Message = "Comment1", UserId = "*****@*****.**", LotId = 1
            };
            await lotCommentOperationsHandler.AddCommentAsync(lotComment);

            var lotComment2 = new LotComment {
                Message = "Comment2", UserId = "*****@*****.**", LotId = 1
            };
            await lotCommentOperationsHandler.AddCommentAsync(lotComment2);

            var resultLot = await lotOperationsHandler.GetLotAsync(1);

            resultLot.LotComments = lotCommentOperationsHandler.GetLotComments(resultLot.Id).ToList();
            var resultUser = await userAccountOperationsHandler.GetUserAccountAsync("*****@*****.**");

            resultUser.LotComments = lotCommentOperationsHandler.GetUserComments(resultUser.Email).ToList();

            Assert.AreEqual(1, (await lotOperationsHandler.GetAllLotsAsync()).Count());
            Assert.AreEqual(2, resultLot.LotComments.Count());
            Assert.AreEqual(2, resultUser.LotComments.Count());
            Assert.AreEqual("Comment1", resultLot.LotComments[0].Message);
            Assert.AreEqual("DefaultUser", resultLot.LotComments[0].User.Name);
            Assert.AreEqual("Comment2", resultLot.LotComments[1].Message);
            Assert.AreEqual("DefaultUser", resultLot.LotComments[1].User.Name);
        }
示例#2
0
        public void AddLot_InvalidInput_ThrowsExceptions()
        {
            var invalidEmailLot = new Lot {
                SellerUserId = "*****@*****.**", SellDate = DateTime.Now.AddDays(1), StartDate = DateTime.Now
            };
            var invalidDatesLot = new Lot {
                SellerUserId = "*****@*****.**", SellDate = DateTime.Now, StartDate = DateTime.Now.AddDays(1)
            };

            Assert.ThrowsAsync <WrongIdException>(() => lotOperationsHandler.AddLotAsync(invalidEmailLot, "", ""));
            Assert.ThrowsAsync <WrongModelException>(() => lotOperationsHandler.AddLotAsync(invalidDatesLot, "", ""));
        }
        public async Task DeleteUserAccountAsync_ValidId_DeletesWithCommentsAndLots()
        {
            var user = new UserAccountInfo {
                Name = "User1", Email = "*****@*****.**"
            };
            var comment1 = new LotComment {
                Message = "Message1", UserId = "*****@*****.**", LotId = 1
            };
            var comment2 = new LotComment {
                Message = "Message2", UserId = "*****@*****.**", LotId = 1
            };
            var lot = new Lot {
                SellerUserId = "*****@*****.**", StartDate = DateTime.Now, SellDate = DateTime.Now.AddDays(1),
            };
            await userAccountOperationsHandler.AddUserAccountAsync(user);

            await lotOperationsHandler.AddLotAsync(lot, "", "");

            await lotCommentOperationsHandler.AddCommentAsync(comment1);

            await lotCommentOperationsHandler.AddCommentAsync(comment2);

            await userAccountOperationsHandler.DeleteUserAccountAsync("*****@*****.**", "", "");

            Assert.AreEqual(0, (await userAccountOperationsHandler.GetAllUserAccountsAsync()).Count());
            //Lot was deleted together with user, so lot with Id = 1 doesn`t exist
            Assert.ThrowsAsync <WrongIdException>(() => lotOperationsHandler.GetLotAsync(1));
        }
示例#4
0
 // POST api/<controller>
 public async System.Threading.Tasks.Task <IHttpActionResult> PostLotAsync([FromBody] LotModel value)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     value.SellerUserId = User.Identity.Name;
     try
     {
         await lotOperationsHandler.AddLotAsync(mapper.Map <Lot>(value), System.Web.Hosting.HostingEnvironment.MapPath(@"~"), Request.RequestUri.GetLeftPart(UriPartial.Authority));
     }
     catch (WrongIdException ex)
     {
         return(Content(HttpStatusCode.NotFound, ex.Message));
     }
     catch (WrongModelException ex)
     {
         return(BadRequest(ex.Message));
     }
     catch (Exception ex)
     {
         return(InternalServerError(ex));
     }
     return(Ok());
 }
        public async Task AddLotAsync_ValidInput_AddsLotToDB()
        {
            var lot = new Lot {
                SellerUserId = "*****@*****.**", SellDate = DateTime.Now.AddDays(1), StartDate = DateTime.Now
            };

            await lotOperationsHandler.AddLotAsync(lot, "", "");

            Assert.AreEqual(1, (await lotOperationsHandler.GetAllLotsAsync()).Count());
        }