Exemple #1
0
        public void PostPutInShoppingCartTest()
        {
            Database.SetInitializer(new BikePortalDbTestInitializer());
            var container         = UnityConfig.Container;
            var bikeBll           = container.Resolve <IBikeBll>();
            var userBll           = new Mock <IUserBll>();
            var mapper            = BikePortalMapper.Create();
            var articleController = new BikeController(bikeBll, mapper, userBll.Object);

            articleController.Request = new HttpRequestMessage();

            var bikes       = articleController.Get();
            var firstBikeId = bikes.First().Id;
            var comments    = articleController.GetComments(firstBikeId).ToList();

            var user = User.Create("name", "name");

            userBll.Setup(u => u.GetUser(It.IsAny <string>())).Returns(user);

            var commentText = "hello wordl";

            var commentBindingModel = new CommentBindingModel
            {
                CommentText = commentText
            };

            var responseTask = articleController.PostComment(firstBikeId, commentBindingModel);
            var message      = responseTask.ExecuteAsync(new CancellationToken()).Result;

            Assert.AreEqual(message.StatusCode, HttpStatusCode.OK);

            var updatedBikeComments = articleController.GetComments(firstBikeId).ToList();

            Assert.AreEqual(comments.Count() + 1, updatedBikeComments.Count());
        }
Exemple #2
0
        public void PostTest()
        {
            var container      = UnityConfig.Container;
            var bikeBll        = container.Resolve <IBikeBll>();
            var userBll        = new Mock <IUserBll>();
            var bikeController = new BikeController(bikeBll, BikePortalMapper.Create(), userBll.Object);

            bikeController.Request = new HttpRequestMessage();

            var user = User.Create("name", "name");

            userBll.Setup(u => u.GetUser(It.IsAny <string>())).Returns(user);

            var description = "description";
            var model       = "model of bike";
            var price       = 123M;
            var name        = "name of bike";

            var bikeBindingModel = new BikeBindingModel
            {
                Description = description,
                Model       = model,
                Price       = price,
                Name        = name
            };
            var responseTask = bikeController.Post(bikeBindingModel);
            var message      = responseTask.ExecuteAsync(new CancellationToken()).Result;

            Assert.AreEqual(message.StatusCode, HttpStatusCode.OK);

            var bikeViewModel = bikeController.Get();

            Assert.IsTrue(bikeViewModel.Any());
        }