public void Test_UserOwner_AlreadyOwned()
        {
            var user = new User("username", "emailAddress");
            var item = new Item("Title", "Creator", "Edition");
            var expectedOwnership = new Ownership<User>(item, user);
            SaveEntities(user, item, expectedOwnership);

            CommitTransactionAndOpenNew();

            var request = new AddUserItemRequest()
            {
                OwnerId = user.Id,
                Creator = item.Creator,
                Edition = item.Edition,
                Title = item.Title
            };

            var expectedResponse = new BaseResponse(AddItemRequestHandler<User>.OwnershipAlreadyExists);

            var sut = new AddItemRequestHandler<User>(() => Session);
            BaseResponse actualResponse = sut.HandleRequest(request);

            actualResponse.ShouldEqual(expectedResponse);

            CommitTransactionAndOpenNew();

            Ownership<User> ownershipInDb = Session
                .QueryOver<Ownership>()
                .JoinQueryOver<Item>(x => x.Item)
                .Where(x => x.Id == item.Id)
                .SingleOrDefault<Ownership<User>>()
                ;

            ownershipInDb.ShouldEqual(expectedOwnership);
        }
        public void Test_Success()
        {
            //Arrange
            var fromUser = new User("from", "fromEmail");
            var toUser = new User("to", "toEmail");

            SaveEntities(fromUser, toUser);

            CommitTransactionAndOpenNew();

            var expectedConnection = new Connection(fromUser, toUser);
            var expectedResponse = new BaseResponse();
            var request = new ConnectRequest() {FromUserId = fromUser.Id, ToUserId = toUser.Id};

            //Act

            var sut = new ConnectRequestHandler(() => Session);
            BaseResponse actualResponse = sut.HandleRequest(request);

            //Assert

            actualResponse.ShouldEqual(expectedResponse);

            //Check that the connection was saved in the DB
            CommitTransactionAndOpenNew();

            Connection actualConnection = Session
                .QueryOver<Connection>()
                .SingleOrDefault()
                ;

            actualConnection.ShouldEqual(expectedConnection);
        }
        public void Test_AlreadyConnected()
        {
            //Arrange
            var fromUser = new User("from", "fromEmail");
            var toUser = new User("to", "toEmail");
            var existingConnection = new Connection(fromUser, toUser);

            SaveEntities(fromUser, toUser, existingConnection);

            CommitTransactionAndOpenNew();

            var expectedResponse = new BaseResponse(ConnectRequestHandler.AlreadyConnected);
            var request = new ConnectRequest() { FromUserId = fromUser.Id, ToUserId = toUser.Id };

            //Act

            var sut = new ConnectRequestHandler(() => Session);
            BaseResponse actualResponse = sut.HandleRequest(request);

            //Assert

            actualResponse.ShouldEqual(expectedResponse);

            //Check that the connection wasn't saved in the DB
            int numberOfConnections = Session
                .QueryOver<Connection>()
                .RowCount()
                ;

            Assert.That(numberOfConnections, Is.EqualTo(1));
        }
        public void Test_Failed_UsernameTaken()
        {
            //Arrange
            var request = new AddUserRequest() { EmailAddress = "*****@*****.**", UserName = "******"};
            var expectedResponse = new BaseResponse() { Success = false, FailureDescription = AddUserRequestHandler.UsernameTaken };

            var existingUser = new User(request.UserName, "new email address");
            Session.Save(existingUser);

            CommitTransactionAndOpenNew();

            //Act
            var sut = new AddUserRequestHandler(() => Session);
            BaseResponse actualResponseBase = sut.HandleRequest(request);

            //Assert
            actualResponseBase.ShouldEqual(expectedResponse);
        }
        public void Test_SuccessWithExistingOtherConnection()
        {
            //Arrange
            var fromUser = new User("from", "fromEmail");
            var toUser = new User("to", "toEmail");
            var otherUser = new User("other", "otherEmail");
            var existingConnection = new Connection(otherUser, toUser);

            SaveEntities(fromUser, toUser, otherUser, existingConnection);

            CommitTransactionAndOpenNew();

            var expectedConnection = new Connection(fromUser, toUser);
            var request = new ConnectRequest() { FromUserId = fromUser.Id, ToUserId = toUser.Id };
            var expectedResponse = new BaseResponse();

            //Act

            var sut = new ConnectRequestHandler(() => Session);
            BaseResponse actualResponse = sut.HandleRequest(request);

            //Assert

            actualResponse.ShouldEqual(expectedResponse);

            //Check that the connection was saved in the DB
            CommitTransactionAndOpenNew();

            Connection connectionAlias = null;
            User user1Alias = null;
            User user2Alias = null;

            Connection actualConnection = Session
                .QueryOver<Connection>(() => connectionAlias)
                .JoinAlias(() => connectionAlias.User1, () => user1Alias)
                .JoinAlias(() => connectionAlias.User2, () => user2Alias)
                .Where(() => (user1Alias.Id == request.FromUserId && user2Alias.Id == request.ToUserId) ||
                             (user1Alias.Id == request.ToUserId && user2Alias.Id == request.FromUserId))
                .SingleOrDefault()
                ;

            actualConnection.ShouldEqual(expectedConnection);
        }
        public void Test_Success()
        {
            var requestor = new User("requestor", "*****@*****.**");
            var owner = new User("owner", "*****@*****.**");
            var item = new Item("title", "creator", "edition");
            var ownership = new Ownership<User>(item, owner);

            SaveEntities(requestor, owner, item, ownership);

            CommitTransactionAndOpenNew();

            var request = new BorrowItemRequest(){OwnershipId = ownership.Id, RequestorId = requestor.Id};
            var expectedResponse = new BaseResponse();

            var expectedBorrowing = new Borrowing(requestor, ownership);

            var sut = new BorrowItemRequestHandler(() => Session);
            BaseResponse actualResponse = sut.HandleRequest(request);

            actualResponse.ShouldEqual(expectedResponse);

            //Check that the right Borrowing object is in the DB
            Borrowing borrowingAlias = null;
            User requestorAllias = null;
            Ownership ownershipAlias = null;

            Borrowing borrowingInDb = Session
                .QueryOver<Borrowing>(() => borrowingAlias)
                .JoinAlias(() => borrowingAlias.Borrower, () => requestorAllias)
                .JoinAlias(() => borrowingAlias.Ownership, () => ownershipAlias)
                .Where(() => requestorAllias.Id == requestor.Id)
                .And(() => ownershipAlias.Id == ownership.Id)
                .SingleOrDefault()
                ;

            borrowingInDb.ShouldEqual(expectedBorrowing);
        }
        public void Test_Success()
        {
            //Arrange
            var request = new AddUserRequest() {EmailAddress = "*****@*****.**", UserName = "******"};
            var expectedResponse = new BaseResponse() {Success = true};

            //Act
            var sut = new AddUserRequestHandler(() => Session);
            BaseResponse actualResponseBase = sut.HandleRequest(request);

            //Assert
            actualResponseBase.ShouldEqual(expectedResponse);

            var expectedUser = new User(request.UserName, request.EmailAddress);

            CommitTransactionAndOpenNew();

            User userInDb = Session
                .QueryOver<User>()
                .SingleOrDefault()
                ;

            userInDb.ShouldEqual(expectedUser);
        }
예제 #8
0
 public Borrowing(User borrower, Ownership ownership)
 {
     Borrower = borrower;
     Ownership = ownership;
     RequestTime = DateTime.Now;
 }
예제 #9
0
 public Connection(User user1, User user2)
 {
     User1 = user1;
     User2 = user2;
 }