Пример #1
0
        public async Task CreateTenant()
        {
            var daprClient              = CreateMockDaprClientWithTenant();
            var tenantService           = new Mock <ITenantService>();
            var tenantPropertiesService = new Mock <ITenantPropertiesService>();

            var tenantCreator = new TenantCreator();

            tenantService.Setup(x => x.CreateAsync(It.IsAny <TenantCreator>())).Returns(
                Task.FromResult(new Tenant("Id1", "name"))
                );

            var tenantController = new TenantController(
                tenantService.Object,
                tenantPropertiesService.Object,
                daprClient.Object
                );

            var result = await tenantController.CreateTenant(tenantCreator);

            var createdAtActionResult = Assert.IsType <CreatedAtActionResult>(result.Result);

            Assert.Equal(nameof(tenantController.FindOne), createdAtActionResult.ActionName);
            var tenant = Assert.IsType <Tenant>(createdAtActionResult.Value);

            Assert.NotNull(tenant);
            Assert.Equal("Id1", tenant.Id);
            Assert.Equal("name", tenant.Name);
            Assert.Null(tenant.Properties);
            daprClient.Verify(x => x.PublishEventAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <TopicData <Tenant> >(), It.IsAny <CancellationToken>()), Times.Once);
        }
Пример #2
0
        public async Task <Tenant> CreateAsync(TenantCreator tenant)
        {
            var tenantId = tenant.Id ?? throw new ArgumentException("Tenant id is mandatory");

            if (await _tenantRepository.ExistsByIdAsync(tenantId))
            {
                throw new IllegalArgumentException(code: "TENANT_EXISTS", message: $"Tenant {tenantId} already exists");
            }
            return(await _tenantRepository.InsertAsync(tenant.ToTenant()));
        }