Beispiel #1
0
            public void GivenCreated_BuildWithCreated()
            {
                // Arrange
                var builder = new InsertLicenseCommandBuilder();
                var created = DateTime.UtcNow;

                // Act
                var result = builder.WithCreated(created);
                var build  = builder.Build();

                // Assert
                Assert.Multiple(() =>
                {
                    Assert.That(result, Is.EqualTo(builder));
                    Assert.That(build.Created, Is.EqualTo(created));
                });
            }
Beispiel #2
0
            public void GivenUserId_BuildsWithUserId()
            {
                // Arrange
                var builder = new InsertLicenseCommandBuilder();
                var userId  = Guid.NewGuid();

                // Act
                var result = builder.WithUserId(userId);
                var build  = builder.Build();

                // Assert
                Assert.Multiple(() =>
                {
                    Assert.That(result, Is.EqualTo(builder));
                    Assert.That(build.UserId, Is.EqualTo(userId));
                });
            }
Beispiel #3
0
            public void GivenKey_BuildsWithKey()
            {
                // Arrange
                var          builder = new InsertLicenseCommandBuilder();
                const string key     = "This is a license key";

                // Act
                var result = builder.WithKey(key);
                var build  = builder.Build();

                // Assert
                Assert.Multiple(() =>
                {
                    Assert.That(result, Is.EqualTo(builder));
                    Assert.That(build.Key, Is.EqualTo(key));
                });
            }
        public async Task <CreatedLicenseDto> CreateAsync(CreateLicenseDto createLicense, CancellationToken token)
        {
            await ValidateUserExistsAsync(createLicense.UserId, token);

            var licenseId  = Guid.NewGuid();
            var licenseKey = await GenerateLicenseKey(createLicense.UserId, token);

            var insertLicenseCommandBuilder = new InsertLicenseCommandBuilder()
                                              .WithId(licenseId)
                                              .WithKey(licenseKey)
                                              .WithCreated(DateTime.UtcNow)
                                              .WithUserId(createLicense.UserId);

            var insertLicenseCommand = insertLicenseCommandBuilder.Build();

            await _mediator.Send(insertLicenseCommand, token);

            return(new CreatedLicenseDto {
                LicenseId = licenseId
            });
        }