Пример #1
0
        public void ConstructorWithModel()
        {
            var id          = Guid.NewGuid();
            var updateModel = Generator.Default.Single <LocationUpdateModel>();

            updateModel.Should().NotBeNull();

            var updateCommand = new EntityUpdateCommand <Guid, LocationUpdateModel, LocationReadModel>(MockPrincipal.Default, id, updateModel);

            updateCommand.Should().NotBeNull();

            updateCommand.Id.Should().NotBe(Guid.Empty);
            updateCommand.Id.Should().Be(id);

            updateCommand.Model.Should().NotBeNull();

            updateCommand.Principal.Should().NotBeNull();
        }
Пример #2
0
        public async Task UpdateLocation()
        {
            var original = Generator.Default.Single <Location>();

            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <LocationCreateModel, Location>();
                cfg.CreateMap <LocationUpdateModel, Location>();
                cfg.CreateMap <Location, LocationReadModel>();
            });
            var mapper = new Mapper(config);

            var options = new DbContextOptionsBuilder <SampleContext>()
                          .UseInMemoryDatabase(databaseName: "UpdateLocation")
                          .Options;

            var context = new SampleContext(options);

            context.Locations.Add(original);
            context.SaveChanges();

            var updateModel = Generator.Default.Single <LocationUpdateModel>();

            updateModel.Should().NotBeNull();

            var updateCommand = new EntityUpdateCommand <Guid, LocationUpdateModel, LocationReadModel>(MockPrincipal.Default, original.Id, updateModel);

            updateCommand.Should().NotBeNull();
            updateCommand.Model.Should().NotBeNull();
            updateCommand.Principal.Should().NotBeNull();

            var updateCommandHandler = new EntityUpdateCommandHandler <SampleContext, Location, Guid, LocationUpdateModel, LocationReadModel>(NullLoggerFactory.Instance, context, mapper);
            var readModel            = await updateCommandHandler.Handle(updateCommand, CancellationToken.None);

            readModel.Should().NotBeNull();
            readModel.Id.Should().NotBe(Guid.Empty);
            readModel.Id.Should().Be(original.Id);

            readModel.Name.Should().Be(updateModel.Name);
        }