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);
        }
Exemplo n.º 2
0
        public void Test_UserOwner_NewItem_Success()
        {
            var user         = DefaultTestData.ServiceStackUser1;
            var expectedItem = new Item("Title", "Creator", "Edition");

            SaveEntities(user);

            CommitTransactionAndOpenNew();

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

            var expectedResponse = new BaseResponse();

            var expectedOwnership = new Ownership <User>(expectedItem, user);

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

            actualResponse.ShouldEqual(expectedResponse);

            CommitTransactionAndOpenNew();

            Item itemInDb = Session
                            .QueryOver <Item>()
                            .Where(x => x.Title == expectedItem.Title)
                            .Where(x => x.Creator == expectedItem.Creator)
                            .Where(x => x.Edition == expectedItem.Edition)
                            .SingleOrDefault()
            ;

            itemInDb.ShouldEqual(expectedItem);

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

            ownershipInDb.ShouldEqual(expectedOwnership);
        }
Exemplo n.º 3
0
        public void Test_OrgOwner_ItemExists_Success()
        {
            var user         = DefaultTestData.ServiceStackUser1;
            var organisation = new Organisation("organisation");
            var item         = new Item("Title", "Creator", "Edition");

            SaveEntities(user, organisation, item);

            CommitTransactionAndOpenNew();

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

            var expectedResponse = new BaseResponse();

            var expectedOwnership = new Ownership <Organisation>(item, organisation);

            var          sut            = new AddItemRequestHandler <Organisation>(() => Session);
            BaseResponse actualResponse = sut.HandleRequest(request, user.Id);

            actualResponse.ShouldEqual(expectedResponse);

            CommitTransactionAndOpenNew();

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

            ownershipInDb.ShouldEqual(expectedOwnership);
        }
        public void Test_OrgOwner_ItemExists_Success()
        {
            var user = DefaultTestData.ServiceStackUser1;
            var organisation = new Organisation("organisation");
            var item = new Item("Title", "Creator", "Edition");
            SaveEntities(user, organisation, item);

            CommitTransactionAndOpenNew();

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

            var expectedResponse = new BaseResponse();

            var expectedOwnership = new Ownership<Organisation>(item, organisation);

            var sut = new AddItemRequestHandler<Organisation>(() => Session);
            BaseResponse actualResponse = sut.HandleRequest(request, user.Id);

            actualResponse.ShouldEqual(expectedResponse);

            CommitTransactionAndOpenNew();

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

            ownershipInDb.ShouldEqual(expectedOwnership);
        }
        public void Test_UserOwner_NewItem_Success()
        {
            var user = DefaultTestData.ServiceStackUser1;
            var expectedItem = new Item("Title", "Creator", "Edition");
            SaveEntities(user);

            CommitTransactionAndOpenNew();

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

            var expectedResponse = new BaseResponse();

            var expectedOwnership = new Ownership<User>(expectedItem, user);

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

            actualResponse.ShouldEqual(expectedResponse);

            CommitTransactionAndOpenNew();

            Item itemInDb = Session
                .QueryOver<Item>()
                .Where(x => x.Title == expectedItem.Title)
                .Where(x => x.Creator == expectedItem.Creator)
                .Where(x => x.Edition == expectedItem.Edition)
                .SingleOrDefault()
                ;

            itemInDb.ShouldEqual(expectedItem);

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

            ownershipInDb.ShouldEqual(expectedOwnership);
        }