示例#1
0
        public void Initialize()
        {
            ObjectFactory.Configure(
                x => x.For <TransportMock>().Use(TransportMock.CreateWithoutStructureMapClear(typeof(BugzillaProfile).Assembly,
                                                                                              new List <Assembly>
            {
                typeof(ExceptionThrownLocalMessage).Assembly,
                typeof(BugzillaProfile).Assembly
            },
                                                                                              new Assembly[] {})));
            ObjectFactory.Configure(x =>
            {
                x.For <IBugzillaService>().HybridHttpOrThreadLocalScoped().Use <BugzillaServiceMock>();
                x.Forward <IBugzillaService, BugzillaServiceMock>();
                x.For <IBugConverter <BugzillaBug> >().HybridHttpOrThreadLocalScoped().Use <ConverterComposite>
                    ();
                var bugChunkSize = MockRepository.GenerateStub <IBugChunkSize>();
                bugChunkSize.Stub(y => y.Value).Return(1);
                x.For <IBugChunkSize>().HybridHttpOrThreadLocalScoped().Use(bugChunkSize);
                x.For <IBugzillaInfoStorageRepository>().HybridHttpOrThreadLocalScoped().Use
                <BugzillaInfoStorageRepository>();
                x.For <IBugzillaActionFactory>().HybridHttpOrThreadLocalScoped().Use <BugzillaActionFactory>();
            });

            AddReplyForCreateCommand <BugDTO, BugCreatedMessage>(TpBugs);
            AddReplyForUpdateCommand <BugDTO, BugField, BugUpdatedMessage>(TpBugs, BugField.EntityStateID);
            AddReplyForCreateCommand <CommentDTO, CommentCreatedMessage>(TpComments);
            AddReplyForUpdateCommand <CommentDTO, CommentField, CommentUpdatedMessage>(TpComments);
            AddReplyForCreateCommand <AttachmentDTO, AttachmentCreatedMessage>(TpAttachments);

            AddReplyForCreateCommand <TeamDTO, TeamCreatedMessage>(TpTeams);
            TransportMock.OnDeleteEntityCommand <TeamDTO>().Reply(
                x =>
            {
                var dto =
                    ObjectFactory.GetInstance <IStorageRepository>().Get <TeamDTO>().SingleOrDefault(teamDto => teamDto.ID == x.ID);

                var teamDeletedMessage = new TeamDeletedMessage {
                    Dto = dto ?? new TeamDTO {
                        ID = x.ID
                    }
                };
                return(teamDeletedMessage);
            });

            AddReplyForQuery <RetrieveAllUsersQuery, UserDTO, UserQueryResult>(Users);
            AddReplyForQuery <EntityStateQuery, EntityStateDTO, EntityStateQueryResult>(EntityStates);
            AddReplyForQuery <PriorityQuery, PriorityDTO, PriorityQueryResult>(Priorities);
            AddReplyForQuery <RetrieveAllSeveritiesQuery, SeverityDTO, SeverityQueryResult>(Severities);
            AddReplyForQuery <RetrieveAllRolesQuery, RoleDTO, RoleQueryResult>(Roles);
            AddReplyForQuery <RetrieveAllProjectsQuery, ProjectDTO, ProjectQueryResult>(Projects);
        }