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());
        }
Exemple #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));
        }
        /// <summary>
        /// Registers the type mappings with the Unity container.
        /// </summary>
        /// <param name="container">The unity container to configure.</param>
        /// <remarks>
        /// There is no need to register concrete types such as controllers or
        /// API controllers (unless you want to change the defaults), as Unity
        /// allows resolving a concrete type even if it was not previously
        /// registered.
        /// </remarks>
        public static void RegisterTypes(IUnityContainer container)
        {
            // NOTE: To load from web.config uncomment the line below.
            // Make sure to add a Unity.Configuration to the using statements.
            // container.LoadConfiguration();

            // TODO: Register your type's mappings here.
            container.RegisterType <IBikePartRepository, BikePartRepository>();
            container.RegisterType <IBikeRepository, BikeRepository>();
            container.RegisterType <IUserRepository, UserRepository>();
            container.RegisterType <IOrderRepository, OrderRepository>();

            container.RegisterType <IBikeBll, BikeBll>();
            container.RegisterType <IUserBll, UserBll>();
            container.RegisterType <IOrderBll, OrderBll>();

            container.RegisterInstance <IMapper>(BikePortalMapper.Create());

            container.RegisterType <AccountController>(new InjectionConstructor());

            container.RegisterType <IBikePortalDbContext, BikePortalDbContext>(new PerThreadLifetimeManager());
        }