Exemplo n.º 1
0
        public void List_User_Bids_Of_NonExisting_User_Should_Return_401Unauthorized()
        {
            // Arrange
            var fakeBids  = this.mocks.BidRepositoryMock.Object.All();
            var fakeUsers = this.mocks.UserRepositoryMock.Object.All();

            var mockContext = new Mock <IBidSystemData>();

            mockContext.Setup(c => c.Bids.All())
            .Returns(fakeBids);
            mockContext.Setup(c => c.Users.All())
            .Returns(fakeUsers);
            var mockUserIdProvider = new Mock <IUserIdProvider>();

            mockUserIdProvider.Setup(uip => uip.GetUserId())
            .Returns(int.MaxValue.ToString);

            var bidsController = new BidsController(mockContext.Object, mockUserIdProvider.Object);

            this.SetupController(bidsController);

            // Act
            var response = bidsController.ListUserBids()
                           .ExecuteAsync(CancellationToken.None).Result;

            // Assert
            Assert.AreEqual(HttpStatusCode.Unauthorized, response.StatusCode);
        }
Exemplo n.º 2
0
        public void List_User_Bids_Of_Existing_And_Logged_User_Should_List_Bids()
        {
            // Arrange
            var fakeBids  = this.mocks.BidRepositoryMock.Object.All();
            var fakeUsers = this.mocks.UserRepositoryMock.Object.All();
            var fakeUser  = this.mocks.UserRepositoryMock.Object.All()
                            .FirstOrDefault();

            if (fakeUser == null)
            {
                Assert.Fail("Cannot perform test - no users available.");
            }

            var mockContext = new Mock <IBidSystemData>();

            mockContext.Setup(c => c.Bids.All())
            .Returns(fakeBids);
            mockContext.Setup(c => c.Users.All())
            .Returns(fakeUsers);
            var mockUserIdProvider = new Mock <IUserIdProvider>();

            mockUserIdProvider.Setup(uip => uip.GetUserId())
            .Returns(fakeUser.Id);

            var bidsController = new BidsController(mockContext.Object, mockUserIdProvider.Object);

            this.SetupController(bidsController);

            // Act
            var response = bidsController.ListUserBids()
                           .ExecuteAsync(CancellationToken.None).Result;
            var results = response.Content.ReadAsAsync <List <BidViewModel> >().Result;

            // Assert
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.AreEqual(2, results.Count);
            Assert.AreEqual("gosho", results[0].Bidder);
            Assert.AreEqual("gosho", results[1].Bidder);
            Assert.AreEqual(99, results[0].Id);
            Assert.AreEqual(55, results[1].Id);
        }