Esempio n. 1
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());
        }
        public void Should_Post_Bike()
        {
            var controller = new BikeController(vehicleStorage.Object, logger.Object);
            var bike       = GetBike();
            var result     = controller.Post(bike);

            Assert.True(result.GetType() == typeof(CreatedResult), "POST Test failed");
        }
Esempio n. 3
0
        public void PostTest()
        {
            // Arrange
            var mockBikeBll = new Mock <IBikeBll>();
            var mapper      = BikePortalMapper.Create();
            var mockUserBll = new Mock <IUserBll>();
            var mockUser    = new Mock <User>();

            mockUserBll.Setup(u => u.GetUser(It.IsAny <string>())).Returns(mockUser.Object);
            var controller = new BikeController(mockBikeBll.Object, mapper, mockUserBll.Object);

            const string  description = "Wonderful bike";
            const string  model       = "Model";
            const string  name        = "Name";
            const decimal price       = 123M;

            // Act

            var bindingModel = new BikeBindingModel
            {
                Description = description,
                Model       = model,
                Name        = name,
                Price       = price
            };

            controller.Post(bindingModel);

            // Assert

            var bike = new Bike
            {
                Id          = 0,
                Uploader    = mockUser.Object,
                Comments    = new List <Comment>(),
                Description = description,
                Model       = model,
                Name        = name,
                Price       = price
            };

            mockBikeBll.Verify(m => m.Add(bike));
        }