Ejemplo n.º 1
0
        public void Create_ValidParams_AccountReturned()
        {
            //Arrange
            var idGuid    = Guid.Parse("051f8160-ce43-4ac0-b8c2-09707c2bcda3");
            var id        = AccountId.FromGuid(idGuid);
            var ownerGuid = Guid.Parse("4bc0c0e9-7181-45e4-934d-e91c0e7bbd75");
            var ownerId   = UserId.FromGuid(ownerGuid);
            var period    = Period.FromMonth(2020, 9);
            var currency  = CurrencyCode.FromString("EUR");

            //Act
            var account = AccountRoot.Create(id, ownerId, period, currency);

            //Assert
            Assert.IsNotNull(account);
            Assert.AreEqual(idGuid, account.Id);
            Assert.AreEqual(ownerGuid, account.OwnerId.Value);
            Assert.AreEqual(DateTime.Parse("2020-09-01"), account.Period.StartDate);
            Assert.AreEqual(DateTime.Parse("2020-09-30"), account.Period.EndDate);
            Assert.AreEqual("EUR", account.Currency.Value);
            Assert.AreEqual(1, account.GetChanges().Count);
            Assert.AreEqual(typeof(V1.AccountCreated), account.GetChanges()[0].GetType());
            var @event = account.GetChanges()[0] as V1.AccountCreated;

            Assert.AreEqual(idGuid, @event.AccountId);
            Assert.AreEqual(ownerGuid, @event.OwnerId);
            Assert.AreEqual(DateTime.Parse("2020-09-01"), @event.StartDate);
            Assert.AreEqual(DateTime.Parse("2020-09-30"), @event.EndDate);
            Assert.AreEqual("EUR", @event.CurrencyCode);
            Assert.AreEqual(AccountState.AccountStateEnum.Open, account.State.Value);
        }
Ejemplo n.º 2
0
        public void ChangeBooking_BookingDoesNotExist_InvalidOperationException()
        {
            //Arrange
            var bookingIdGuid = Guid.Parse("b9c18f4d-8f11-408d-be7c-c7f022abefb2");
            var bookingId     = BookingId.FromGuid(bookingIdGuid);
            var payment       = Payment.FromDecimal(100.00m, "EUR");
            var bookingDate   = BookingDate.FromString("2020-09-26");
            var description   = Description.FromString("My payment");

            var accountIdGuid = Guid.Parse("9ccf4aa8-cd1e-4044-a183-464c8a8730ec");
            var account       = AccountRoot.Create(
                AccountId.FromGuid(accountIdGuid),
                UserId.FromGuid(Guid.Parse("13f172e2-7189-4506-b232-894bafcd4449")),
                Period.FromMonth(2020, 9),
                CurrencyCode.FromString("EUR"));

            account.BookPayment(bookingId, payment, bookingDate, description);

            var nonExistingBookingId = BookingId.FromGuid(Guid.Parse("58bead84-e4d6-481b-9c7a-b52a36a98c3f"));
            var changedPayment       = Payment.FromDecimal(200.00m, "EUR");
            var changedBookingDate   = BookingDate.FromString("2020-09-01");
            var changedDescription   = Description.FromString("My payment changed");

            //Act & Assert
            Assert.Throws <InvalidOperationException>(() => account.ChangeBooking(nonExistingBookingId, changedPayment, changedBookingDate, changedDescription));
        }
Ejemplo n.º 3
0
        protected override void SetStateByEvent(IEvent @event)
        {
            switch (@event)
            {
            case AdvertisementCreated e:
                Id      = e.Id;
                OwnerId = UserId.FromGuid(e.OwnerId);
                State   = AdvertisementState.Inactive;
                break;

            case AdvertisementPriceUpdated e:
                Price = new Price(Rial.FromLong(e.Price));
                break;

            case AdvertisementSentForReview e:
                State = AdvertisementState.ReviewPending;
                break;

            case AdvertisementDescriptionUpdated e:
                Description = AdvertisementDescription.FromString(e.Description);
                break;

            case AdvertisementTitleUpdated e:
                Title = AdvertisementTitle.FromString(e.Title);
                break;

            default:
                throw new InvalidOperationException("امکان اجرای عملیات درخواستی وجود ندارد");
            }
        }
Ejemplo n.º 4
0
        public async Task <DomainValidationResult <UserProfile> > CreateProfileAsync(
            User user,
            string firstName,
            string lastName,
            Gender gender
            )
        {
            var result = new DomainValidationResult <UserProfile>();

            if (user.Profile != null)
            {
                result.AddFailedPreconditionError("The user's profile has already been created.");
            }

            if (result.IsValid)
            {
                var profile = new UserProfile(firstName, lastName, gender);

                user.Create(profile);

                //await this.UpdateSecurityStampAsync(user);

                await this.UpdateUserAsync(user);

                await _publisher.PublishUserProfileChangedIntegrationEventAsync(UserId.FromGuid(user.Id), profile);

                return(profile);
            }

            return(result);
        }
        protected async override Task <ClearanceRoot> Apply(OpenClearanceCommand command, CancellationToken cancellationToken)
        {
            var clearanceDto = await clearanceDtoRepository.GetClearanceIdForUserOnPeriod(command.UserId, command.StartDate, command.EndDate);

            if (clearanceDto == null)
            {
                var clearance = await ClearanceRoot.Open(
                    Domain.ClearanceId.FromGuid(command.ClearanceId),
                    Kernel.UserId.FromGuid(command.UserId),
                    Domain.AccountId.FromGuid(command.AccountId),
                    Kernel.Period.FromStartAndEndDate(command.StartDate, command.EndDate),
                    userSettingsService,
                    clearanceDtoRepository
                    );

                return(clearance);
            }
            else
            {
                AggregateRoot = await GetAggregateFromRepo();

                AggregateRoot.AddAccount(UserId.FromGuid(command.UserId), AccountId.FromGuid(command.AccountId));

                return(AggregateRoot);
            }
        }
Ejemplo n.º 6
0
        public async Task <DomainValidationResult <Doxatag> > ChangeDoxatagAsync(User user, string doxatagName)
        {
            var result = new DomainValidationResult <Doxatag>();

            if (result.IsValid)
            {
                var codes = await _doxatagRepository.FetchDoxatagCodesByNameAsync(doxatagName);

                var code = Doxatag.GenerateUniqueCode(codes);

                var doxatag = new Doxatag(
                    UserId.FromGuid(user.Id),
                    doxatagName,
                    code,
                    new UtcNowDateTimeProvider());

                _doxatagRepository.Create(doxatag);

                await _doxatagRepository.UnitOfWork.CommitAsync();

                return(doxatag);
            }

            return(result);
        }
Ejemplo n.º 7
0
        public async Task EditCustomer(Guid customerId, Customer editedCustomer)
        {
            Customer customer = await _customerRepository.Get(UserId.FromGuid(customerId));

            customer.Edit(editedCustomer);
            await _customerRepository.Update(customer);
        }
Ejemplo n.º 8
0
        public void ChangeBooking_BookingWithDifferentCurrency_PaymentNotSameCurrencyAsAccountException()
        {
            //Arrange
            var bookingIdGuid = Guid.Parse("b9c18f4d-8f11-408d-be7c-c7f022abefb2");
            var bookingId     = BookingId.FromGuid(bookingIdGuid);
            var payment       = Payment.FromDecimal(100.00m, "EUR");
            var bookingDate   = BookingDate.FromString("2020-09-26");
            var description   = Description.FromString("My payment");

            var accountIdGuid = Guid.Parse("9ccf4aa8-cd1e-4044-a183-464c8a8730ec");
            var account       = AccountRoot.Create(
                AccountId.FromGuid(accountIdGuid),
                UserId.FromGuid(Guid.Parse("13f172e2-7189-4506-b232-894bafcd4449")),
                Period.FromMonth(2020, 9),
                CurrencyCode.FromString("EUR"));

            account.BookPayment(bookingId, payment, bookingDate, description);

            var changedPayment     = Payment.FromDecimal(200.00m, "USD");
            var changedBookingDate = BookingDate.FromString("2020-09-01");
            var changedDescription = Description.FromString("My payment changed");

            //Act & Assert
            Assert.Throws <PaymentNotSameCurrencyAsAccountException>(() => account.ChangeBooking(bookingId, changedPayment, changedBookingDate, changedDescription));
        }
Ejemplo n.º 9
0
 public Task Handle(V1.Create command)
 => Handle(
     command.ClassifiedAdId,
     state => ClassifiedAd.Create(
         ClassifiedAdId.FromGuid(command.ClassifiedAdId),
         UserId.FromGuid(command.SellerId)
         )
     );
Ejemplo n.º 10
0
#pragma warning disable CC0068  // Unused Method
#pragma warning disable IDE0051 // Remove unused private members
#pragma warning disable CC0057  // Unused parameters
#pragma warning disable IDE0060 // Remove unused parameter
        private void Handle(V1.AccountCreated @event)
        {
            Id       = @event.AccountId;
            OwnerId  = UserId.FromGuid(@event.OwnerId);
            Period   = Period.FromStartAndEndDate(@event.StartDate, @event.EndDate);
            State    = AccountState.CreateOpen();
            Currency = CurrencyCode.FromString(@event.CurrencyCode);
        }
Ejemplo n.º 11
0
        public void UserId_DefaultGuid_ArgumentNullException()
        {
            //Arrange
            var guid = Guid.Empty;

            //Act & Assert
            Assert.Throws <ArgumentNullException>(() => UserId.FromGuid(guid));
        }
 public Task Handle(V1.CreateOrder command)
 => Handle(
     command.OrderId,
     state => Order.Create(
         OrderId.FromGuid(command.OrderId),
         ClassifiedAdId.FromGuid(command.ClassifiedAdId),
         UserId.FromGuid(command.CustomerId)
         )
     );
Ejemplo n.º 13
0
        public ClassifiedAdsCommandService(
            IAggregateStore store,
            ICurrencyLookup currencyLookup,
            UploadFile uploader) : base(store)
        {
            CreateWhen <V1.Create>(
                cmd => ClassifiedAdId.FromGuid(cmd.Id),
                (cmd, id) => ClassifiedAd.Create(
                    ClassifiedAdId.FromGuid(id),
                    UserId.FromGuid(cmd.OwnerId)
                    )
                );

            UpdateWhen <V1.ChangeTitle>(
                cmd => ClassifiedAdId.FromGuid(cmd.Id),
                (ad, cmd)
                => ad.SetTitle(ClassifiedAdTitle.FromString(cmd.Title))
                );

            UpdateWhen <V1.UpdateText>(
                cmd => ClassifiedAdId.FromGuid(cmd.Id),
                (ad, cmd)
                => ad.UpdateText(ClassifiedAdText.FromString(cmd.Text))
                );

            UpdateWhen <V1.UpdatePrice>(
                cmd => ClassifiedAdId.FromGuid(cmd.Id),
                (ad, cmd) => ad.UpdatePrice(
                    Price.FromDecimal(
                        cmd.Price, cmd.Currency ?? "EUR", currencyLookup
                        )
                    )
                );

            UpdateWhen <V1.RequestToPublish>(
                cmd => ClassifiedAdId.FromGuid(cmd.Id),
                (ad, cmd) => ad.RequestToPublish()
                );

            UpdateWhen <V1.Publish>(
                cmd => ClassifiedAdId.FromGuid(cmd.Id),
                (ad, cmd) => ad.Publish(UserId.FromGuid(cmd.ApprovedBy))
                );

            UpdateWhen <V1.Delete>(
                cmd => ClassifiedAdId.FromGuid(cmd.Id),
                (ad, cmd) => ad.Delete()
                );

            UpdateWhen <V1.UploadImage>(
                cmd => ClassifiedAdId.FromGuid(cmd.Id),
                async(ad, cmd) => ad.AddPicture(
                    await uploader(cmd.Image), new PictureSize(2000, 2000)
                    )
                );
        }
Ejemplo n.º 14
0
        public async Task ShouldBeHttpStatusCodeOK()
        {
            var users   = TestData.FileStorage.GetUsers();
            var user    = users.First();
            var factory = TestHost.WithClaimsFromBearerAuthentication(new Claim(JwtClaimTypes.Subject, user.Id.ToString()));

            _httpClient = factory.CreateClient();
            var testServer = factory.Server;

            testServer.CleanupDbContext();

            await testServer.UsingScopeAsync(
                async scope =>
            {
                var userManager = scope.GetRequiredService <IUserService>();

                await userManager.CreateAsync(user);

                var addressService = scope.GetRequiredService <IAddressService>();

                var result = await addressService.AddAddressAsync(
                    UserId.FromGuid(user.Id),
                    Country.Canada,
                    "1234 Test Street",
                    null,
                    "Toronto",
                    "ON",
                    "A1A 1A1");

                result.IsValid.Should().BeTrue();

                var addressBook = await addressService.FetchAddressBookAsync(user);

                // Act
                using var response = await this.ExecuteAsync(
                          addressBook.First().Id,
                          new UpdateAddressRequest
                {
                    CountryIsoCode = EnumCountryIsoCode.CA,
                    Line1          = "1234 Test Street",
                    Line2          = null,
                    City           = "Toronto",
                    State          = "ON",
                    PostalCode     = "A1A 1A1"
                });

                // Assert
                response.EnsureSuccessStatusCode();

                response.StatusCode.Should().Be(HttpStatusCode.OK);

                var message = await response.Content.ReadAsStringAsync();

                message.Should().NotBeNullOrWhiteSpace();
            });
        }
        protected async override Task <AccountRoot> Apply(CreateCommand command, CancellationToken cancellationToken)
        {
            var account = AccountRoot.Create(
                AccountId.FromGuid(command.AccountDto.Id),
                UserId.FromGuid(command.AccountDto.OwnerId),
                Period.FromMonth(command.AccountDto.Year, command.AccountDto.Month),
                CurrencyCode.FromString(command.AccountDto.Currency));

            return(await Task.FromResult(account));
        }
Ejemplo n.º 16
0
        public void GetUsers_ShouldContainAdminId()
        {
            // Arrange
            var storage = TestData.FileStorage;

            // Act
            var users = storage.GetUsers();

            // Assert
            users.Should().Contain(userId => userId == UserId.FromGuid(Guid.Parse("e4655fe0-affd-4323-b022-bdb2ebde6091")));
        }
Ejemplo n.º 17
0
        public void UserId_ValidGuid_Created()
        {
            //Arrange
            var guid = Guid.Parse("dca2b44e-6ea7-4812-8c2f-ca772512ca01");

            //Act
            var userId = UserId.FromGuid(guid);

            //Assert
            Assert.AreEqual(guid, userId.Value);
        }
Ejemplo n.º 18
0
        public void Handle(CreateCommand command)
        {
            if (_repository.Exists(command.Id))
            {
                throw new InvalidOperationException($"قبلا آگهی با شناسه {command.Id} ثبت شده است.");
            }

            var advertisement = new Advertisement(command.Id, UserId.FromGuid(command.OwnerId));

            _repository.Add(advertisement);
            _unitOfWork.Commit();
        }
Ejemplo n.º 19
0
        public void Entities_With_Same_Id_Are_Equals()
        {
            //arrange
            var userId = UserId.FromGuid(Guid.NewGuid());
            //act
            var user        = new User(userId, "Manuel", "Hernández", "*****@*****.**", "Software Developer");
            var userUpdated = new User(userId, "Angel", "Garcia", "*****@*****.**", "Staff Software Developer");
            //assert
            bool isTrue = user.Equals(userUpdated) && user == userUpdated &&
                          user.GetHashCode() == userUpdated.GetHashCode();

            Assert.True(isTrue);
        }
        public async Task <bool> Handle(UploadUserProfilePhotoCommand request, CancellationToken cancellationToken)
        {
            var user = await _userRepository.GetAsync(UserId.FromGuid(request.UserId));

            if (user == null)
            {
                throw new UserNotFoundException("User not found");
            }

            user.UploadPhoto(request.FileName, request.Photo);

            await _userRepository.UnitOfWork.CommitChanges();

            return(true);
        }
Ejemplo n.º 21
0
        public async Task ShouldBeHttpStatusCodeOK()
        {
            var users   = TestData.FileStorage.GetUsers();
            var user    = users.First();
            var factory = TestHost.WithClaimsFromBearerAuthentication(new Claim(JwtClaimTypes.Subject, user.Id.ToString()));

            _httpClient = factory.CreateClient();
            var testServer = factory.Server;

            testServer.CleanupDbContext();

            await testServer.UsingScopeAsync(
                async scope =>
            {
                var userManager = scope.GetRequiredService <IUserService>();

                await userManager.CreateAsync(user);

                var addressService = scope.GetRequiredService <IAddressService>();

                var result = await addressService.AddAddressAsync(
                    UserId.FromGuid(user.Id),
                    Country.Canada,
                    "1234 Test Street",
                    null,
                    "Toronto",
                    "Ontario",
                    "A1A1A1");

                result.IsValid.Should().BeTrue();

                var addressBook = await addressService.FetchAddressBookAsync(user);

                // Act
                using var response = await this.ExecuteAsync();

                // Assert
                response.EnsureSuccessStatusCode();

                response.StatusCode.Should().Be(HttpStatusCode.OK);

                var mapper = scope.GetRequiredService <IMapper>();

                var addressResponse = await response.Content.ReadAsJsonAsync <ICollection <AddressDto> >();

                addressResponse.Should().BeEquivalentTo(mapper.Map <ICollection <AddressDto> >(addressBook));
            });
        }
Ejemplo n.º 22
0
        public void Entities_With_Different_Id_Are_Not_Equals()
        {
            //arrange
            var userId       = UserId.FromGuid(Guid.NewGuid());
            var updateUserId = UserId.FromGuid(Guid.NewGuid());
            //act
            var user = new User(userId, "Manuel", "Hernández",
                                "*****@*****.**", "Software Developer");
            var userUpdated = new User(updateUserId, "Manuel", "Hernández",
                                       "*****@*****.**", "Software Developer");
            //assert
            bool isTrue = !user.Equals(userUpdated) && user != userUpdated &&
                          user.GetHashCode() != userUpdated.GetHashCode();

            Assert.True(isTrue);
        }
        protected override void When(object @event)
        {
            Picture picture;

            switch (@event)
            {
            case V1.ClassifiedAdCreated e:
                Id        = e.Id;
                OwnerId   = UserId.FromGuid(e.OwnerId);
                State     = ClassifiedAdState.Inactive;
                _pictures = new List <Picture>();
                break;

            case V1.ClassifiedAdTitleChanged e:
                Title = new ClassifiedAdTitle(e.Title);
                break;

            case V1.ClassifiedAdTextUpdated e:
                Text = new ClassifiedAdText(e.AdText);
                break;

            case V1.ClassifiedAdPriceUpdated e:
                Price = new Price(e.Price, e.CurrencyCode);
                break;

            case V1.ClassifiedAdSentForReview _:
                State = ClassifiedAdState.PendingReview;
                break;

            case V1.ClassifiedAdPublished e:
                ApprovedBy = UserId.FromGuid(e.ApprovedBy);
                State      = ClassifiedAdState.Active;
                break;

            // picture
            case V1.PictureAddedToAClassifiedAd e:
                picture = new Picture(Apply);
                ApplyToEntity(picture, e);
                _pictures.Add(picture);
                break;

            case V1.ClassifiedAdPictureResized e:
                picture = FindPicture(new PictureId(e.PictureId));
                ApplyToEntity(picture, @event);
                break;
            }
        }
Ejemplo n.º 24
0
        public void ChangeBooking_ValidParams_BookingAddedToAccount()
        {
            //Arrange
            var bookingIdGuid = Guid.Parse("b9c18f4d-8f11-408d-be7c-c7f022abefb2");
            var bookingId     = BookingId.FromGuid(bookingIdGuid);
            var payment       = Payment.FromDecimal(100.00m, "EUR");
            var bookingDate   = BookingDate.FromString("2020-09-26");
            var description   = Description.FromString("My payment");

            var accountIdGuid = Guid.Parse("9ccf4aa8-cd1e-4044-a183-464c8a8730ec");
            var account       = AccountRoot.Create(
                AccountId.FromGuid(accountIdGuid),
                UserId.FromGuid(Guid.Parse("13f172e2-7189-4506-b232-894bafcd4449")),
                Period.FromMonth(2020, 9),
                CurrencyCode.FromString("EUR"));

            account.BookPayment(bookingId, payment, bookingDate, description);

            var changedPayment     = Payment.FromDecimal(200.00m, "EUR");
            var changedBookingDate = BookingDate.FromString("2020-09-20");
            var changedDescription = Description.FromString("My payment changed");

            //Act
            account.ChangeBooking(bookingId, changedPayment, changedBookingDate, changedDescription);

            //Assert
            Assert.IsNotNull(account.Bookings);
            Assert.IsNotNull(account.Bookings[0]);
            var booking = account.Bookings[0];

            Assert.AreEqual(bookingIdGuid, booking.Id.Value);
            Assert.AreEqual(200.00m, booking.Payment.Amount);
            Assert.AreEqual("EUR", booking.Payment.CurrencyCode);
            Assert.AreEqual(DateTime.Parse("2020-09-20"), booking.Date.Value);
            Assert.AreEqual("My payment changed", booking.Description.Value);
            Assert.AreEqual(3, account.GetChanges().Count);
            Assert.AreEqual(typeof(V1.BookingChanged), account.GetChanges()[2].GetType());
            var @event = account.GetChanges()[2] as V1.BookingChanged;

            Assert.AreEqual(accountIdGuid, @event.AccountId);
            Assert.AreEqual(bookingIdGuid, @event.BookingId);
            Assert.AreEqual(200.00m, @event.Amount);
            Assert.AreEqual("EUR", @event.CurrencyCode);
            Assert.AreEqual(DateTime.Parse("2020-09-20"), @event.Date);
            Assert.AreEqual("My payment changed", @event.Description);
        }
        private async Task SeedAdministratorAsync()
        {
            if (!await Users.AnyAsync(user => user.Id == AppAdministrator.Id))
            {
                var user = new User(UserId.FromGuid(AppAdministrator.Id), "*****@*****.**");

                Users.Add(user);

                await this.CommitAsync();

                Logger.LogInformation("The administrator being populated.");
            }
            else
            {
                Logger.LogInformation("The administrator already populated.");
            }
        }
Ejemplo n.º 26
0
        public static Participant ToEntity(this ParticipantModel model)
        {
            var participant = new Participant(
                ParticipantId.FromGuid(model.Id),
                UserId.FromGuid(model.UserId),
                PlayerId.Parse(model.PlayerId),
                new DateTimeProvider(model.RegisteredAt));

            if (model.SynchronizedAt.HasValue && model.Matches != null)
            {
                participant.Snapshot(model.Matches.Select(match => match.ToEntity()), new DateTimeProvider(model.SynchronizedAt.Value));
            }

            participant.ClearDomainEvents();

            return(participant);
        }
Ejemplo n.º 27
0
        public void Close_AccountAlreadyClosed_InvalidOperationException()
        {
            //Arrange
            var idGuid    = Guid.Parse("051f8160-ce43-4ac0-b8c2-09707c2bcda3");
            var id        = AccountId.FromGuid(idGuid);
            var ownerGuid = Guid.Parse("4bc0c0e9-7181-45e4-934d-e91c0e7bbd75");
            var ownerId   = UserId.FromGuid(ownerGuid);
            var period    = Period.FromMonth(2020, 9);
            var currency  = CurrencyCode.FromString("EUR");

            var account = AccountRoot.Create(id, ownerId, period, currency);

            account.Close();

            //Act & Assert
            Assert.Throws <InvalidOperationException>(() => account.Close());
        }
Ejemplo n.º 28
0
        public void BookPayment_PaymentDateOutsidePeriod_InvalidEntityStateException()
        {
            //Arrange
            var bookingIdGuid = Guid.Parse("b9c18f4d-8f11-408d-be7c-c7f022abefb2");
            var bookingId     = BookingId.FromGuid(bookingIdGuid);
            var payment       = Payment.FromDecimal(100.00m, "EUR");
            var bookingDate   = BookingDate.FromString("2020-01-01");
            var description   = Description.FromString("My payment");

            var accountIdGuid = Guid.Parse("9ccf4aa8-cd1e-4044-a183-464c8a8730ec");
            var account       = AccountRoot.Create(
                AccountId.FromGuid(accountIdGuid),
                UserId.FromGuid(Guid.Parse("13f172e2-7189-4506-b232-894bafcd4449")),
                Period.FromMonth(2020, 9),
                CurrencyCode.FromString("EUR"));

            //Act & Assert
            Assert.Throws <InvalidEntityState>(() => account.BookPayment(bookingId, payment, bookingDate, description));
        }
Ejemplo n.º 29
0
        private async Task SeedAdministratorAccountAsync()
        {
            var userId = UserId.FromGuid(AppAdministrator.Id);

            if (!await Accounts.AnyAsync(account => account.Id == userId))
            {
                var account = new Account(userId);

                Accounts.Add(account.ToModel());

                await this.CommitAsync();

                Logger.LogInformation("The administrator account being populated.");
            }
            else
            {
                Logger.LogInformation("The administrator account already populated.");
            }
        }
Ejemplo n.º 30
0
        public async Task RemoveAddressAsync_ShouldBeOkObjectResult()
        {
            // Arrange
            var user = new User
            {
                Id = Guid.NewGuid()
            };

            var address = new Address(
                UserId.FromGuid(user.Id),
                Country.Canada,
                "Line1",
                null,
                "City",
                "State",
                "PostalCode");

            TestMock.UserService.Setup(userManager => userManager.GetUserAsync(It.IsAny <ClaimsPrincipal>())).ReturnsAsync(user).Verifiable();

            TestMock.AddressService.Setup(addressService => addressService.FindUserAddressAsync(It.IsAny <User>(), It.IsAny <AddressId>()))
            .ReturnsAsync(address)
            .Verifiable();

            TestMock.AddressService.Setup(addressService => addressService.RemoveAddressAsync(It.IsAny <Address>()))
            .ReturnsAsync(DomainValidationResult <Address> .Succeeded(address))
            .Verifiable();

            var controller = new AddressBookController(TestMock.UserService.Object, TestMock.AddressService.Object, TestMapper);

            // Act
            var result = await controller.RemoveAddressAsync(address.Id);

            // Assert
            result.Should().BeOfType <OkObjectResult>();

            TestMock.UserService.Verify(userManager => userManager.GetUserAsync(It.IsAny <ClaimsPrincipal>()), Times.Once);

            TestMock.AddressService.Verify(addressService => addressService.FindUserAddressAsync(It.IsAny <User>(), It.IsAny <AddressId>()), Times.Once);

            TestMock.AddressService.Verify(addressService => addressService.RemoveAddressAsync(It.IsAny <Address>()), Times.Once);
        }