Beispiel #1
0
        // Private helper method that sets up a new library DTO
        private LibraryDto SetupLibraryDto()
        {
            var address = new Address()
            {
                LocationAddressLine1  = RandomFactory.GetStreetAddress(),
                LocationAddressLine2  = "",
                LocationCity          = RandomFactory.GetCity(),
                LocationStateProvince = RandomFactory.GetState(),
                LocationZipCode       = RandomFactory.GetZip(),
                LocationCountry       = "US"
            };

            return(new LibraryDto()
            {
                Name = RandomFactory.GetLibraryName(),
                Address = address
            });
        }
        public async Task Create_Valid_PublishesLibraryCreatedDomainEvent()
        {
            await ExecuteWithDb((db) =>
            {
                var handler = new CreateLibraryCommandHandler(
                    MockMediator.Object,
                    db,
                    Mapper,
                    MockAuthorizationService.Object);

                var dto = SetupLibraryDto(RandomFactory.GetLibraryName());

                return(handler.Handle(new CreateLibraryCommand()
                {
                    Library = dto
                }, default));
            }, (result, db) =>
            {
                MockMediator.Verify(x => x.Publish(It.IsAny <LibraryCreatedDomainEvent>(), It.IsAny <CancellationToken>()), Times.Once);
            });
        }
        public async Task Create_MissingAddress_NullReferenceException()
        {
            await ExecuteWithDb((db) =>
            {
                var handler = new CreateLibraryCommandHandler(
                    MockMediator.Object,
                    db,
                    Mapper,
                    MockAuthorizationService.Object);

                var dto = new LibraryDto()
                {
                    Name    = RandomFactory.GetLibraryName(),
                    Address = null
                };

                return(handler.Handle(new CreateLibraryCommand()
                {
                    Library = dto
                }, default));
            });
        }