Пример #1
0
    public async Task <TenantDTO> UpdateTenantAsync(TenantDTO tenantDto)
    {
        Tenant?fromDB = await _context.Tenants.FindAsync(tenantDto.Id);

        if (fromDB == null)
        {
            throw new ItemNotFoundExcepton("Tenant");
        }

        tenantDto.CopyTo(fromDB);
        _context.Entry(fromDB).State = EntityState.Modified;

        try
        {
            await _context.SaveChangesAsync();
        }
        catch (DbUpdateConcurrencyException ex)
        {
            _logger.LogInformation(ex, "Concurrency exception saving changes to {TenatnID}, {TenantName}", fromDB.Id, fromDB.Name);
            throw;
        }

        TenantDTO returnValue = new TenantDTO(fromDB);

        return(returnValue);
    }
Пример #2
0
    public void Over_Rides_Correct_Values_On_Copy(Tenant fromDb, TenantDTO fromUser)
    {
        fromUser.Id      = fromDb.Id;
        fromUser.Version = fromUser.Version != null?Convert.ToBase64String(Encoding.UTF8.GetBytes(fromUser.Version)) : null;

        Assert.NotEqual(fromDb.Name, fromUser.Name);

        fromUser.CopyTo(fromDb);

        AssertAdditions.AllPropertiesAreEqual(fromDb, fromUser, nameof(fromDb.ConcurrencyToken), nameof(fromDb.CreatedTime));
    }
Пример #3
0
    public void User_Cant_Override_Created_Date(Tenant tenant, DateTime original, DateTime updated)
    {
        Assert.NotEqual(original, updated);

        tenant.CreatedTime = original;

        TenantDTO dto = new TenantDTO(tenant)
        {
            CreatedTime = updated
        };

        Assert.NotEqual(tenant.CreatedTime, dto.CreatedTime);

        dto.CopyTo(tenant);
        Assert.Equal(original, tenant.CreatedTime);
    }