コード例 #1
0
        /// <summary>
        /// 注册服务到容器
        /// </summary>
        /// <param name="services"></param>
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();


            //这里就是填写数据库的连接字符串
            var connection = ConfigurationManagerHelper.conn;

            services.AddDbContext <CommunityDbContext>(options => options.UseMySql(connection,
                                                                                   p => p.MigrationsAssembly("Community.Domain")));

            // 使用Swagger
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1.0", new OpenApiInfo {
                    Title = "Community WebaPI", Version = "1.0"
                });
                string str = typeof(Startup).Assembly.GetName().Name;
                // include document file
                c.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, $"{typeof(Startup).Assembly.GetName().Name}.xml"), true);
            });

            //注册领域事件
            DomainEvent.Register();
        }
コード例 #2
0
        public void AssessmentCompletedEventIsRaised()
        {
            var assessment = new Assessment(new Patient(new Organization("Test"), new PersonName("Fed", "Savage"), new DateTime(), Gender.Male));

            var eventRaised = false;

            DomainEvent.Register <AssessmentCompletedEvent> (p => eventRaised = true);

            // Exercise
            assessment.SubmitAssessment();

            // Verify
            Assert.IsTrue(eventRaised);
        }
コード例 #3
0
        public void UserRegisterCommand_Valid_Handle_ShouldReturnSuccessAndRegisterUserProperly()
        {
            //Arrange
            DomainEvent.Register <DomainNotification>(dn => _notifications.Add(dn));

            _mocker.GetMock <IValidationService>()
            .Setup(v => v.Validate(It.IsAny <ICommand>()))
            .Returns(() => true);

            Person person = null;

            var validCommand = new UserRegisterCommandBuilder()
                               .WithPassword("12345")
                               .WithEmail("*****@*****.**");

            _mocker.GetMock <IPersonRepository>()
            .Setup(u => u.GetByEmail(It.IsAny <string>()))
            .Returns(() => null);

            _mocker.GetMock <IPersonRepository>()
            .Setup(u => u.Add(It.IsAny <Person>()))
            .Callback((Person u) =>
            {
                person = new PersonBuilder()
                         .WithPersonId(u.PersonId)
                         .WithSerialKey(u.SerialKey);
            })
            .Returns(() => person);

            var handler = _mocker.Resolve <UserCommandHandler>();

            //Act
            var commandResult = handler.Handle(validCommand);

            //Assert
            _notifications.Should().BeEmpty();
            person.Should().NotBeNull();
            person.PersonId.Should().NotBe(Guid.Empty);
            person.SerialKey.Should().NotBeEmpty();
            person.Active.Should().BeTrue();
            commandResult.Should().BeEquivalentTo(new UserRegisterCommandResult()
            {
                SerialKey = person.SerialKey
            });

            _mocker.GetMock <IValidationService>().Verify(x => x.Validate(It.IsAny <ICommand>()), Times.Once());
            _mocker.GetMock <IPersonRepository>().Verify(x => x.GetByEmail(It.IsAny <string>()), Times.Once());
            _mocker.GetMock <IPersonRepository>().Verify(x => x.Add(It.IsAny <Person>()), Times.Once());
        }