public async Task UpdateExisting() { var audioEngineMock = new Mock <IAudioEngine>(); var serviceMock = new Mock <IModuleConnectionService>(); audioEngineMock.Setup(x => x.RemoveConnection(It.IsAny <long>())).Verifiable(); audioEngineMock.Setup(x => x.AddConnection(It.IsAny <long>())).Verifiable(); serviceMock.Setup(x => x.GetById(It.IsAny <long>())).Returns <long>(id => new ModuleConnectionDto { Id = id }); serviceMock.Setup(x => x.Update(It.IsAny <ModuleConnectionDto>())).Returns(true); var processor = new ModuleConnectionsProcessor(audioEngineMock.Object, serviceMock.Object); var dto = new ModuleConnectionDto { Id = 7, SourceId = 11, SourceConnectorName = "Source!", TargetId = 22, TargetConnectorName = "Target!" }; var result = await processor.ProcessAsync("update", dto).ConfigureAwait(false); Assert.NotNull(result); Assert.True(result.IsSuccess); audioEngineMock.Verify(x => x.RemoveConnection(It.Is <long>(id => id == 7))); audioEngineMock.Verify(x => x.AddConnection(It.Is <long>(id => id == 7))); }
public async Task InsertInvalidDto() { var audioEngineMock = new Mock <IAudioEngine>(); var serviceMock = new Mock <IModuleConnectionService>(); var processor = new ModuleConnectionsProcessor(audioEngineMock.Object, serviceMock.Object); var dto = new ModuleConnectionDto(); var result = await processor.ProcessAsync("insert", dto).ConfigureAwait(false); Assert.NotNull(result); Assert.False(result.IsSuccess); }
/// <inheritdoc /> public bool Update(ModuleConnectionDto dto) { using var dbContext = _dbContextFactory.Create <EngineDbContext>(); var connection = dbContext.ModuleConnections.Find(dto.Id); if (connection == null) { return(false); } connection.SourceModuleId = dto.SourceId; connection.TargetModuleId = dto.TargetId; return(dbContext.SaveChanges() > 0); }
public async Task UpdateNotExisting() { var audioEngineMock = new Mock <IAudioEngine>(); var serviceMock = new Mock <IModuleConnectionService>(); var processor = new ModuleConnectionsProcessor(audioEngineMock.Object, serviceMock.Object); var dto = new ModuleConnectionDto { Id = -1 }; var result = await processor.ProcessAsync("update", dto).ConfigureAwait(false); Assert.NotNull(result); Assert.False(result.IsSuccess); }
private static ModuleConnection GetModuleConnection(ModuleConnectionDto dto) { if (dto == null) { return(null); } return(new ModuleConnection { Id = dto.Id, SourceConnectorName = dto.SourceConnectorName, SourceModuleId = dto.SourceId, TargetConnectorName = dto.TargetConnectorName, TargetModuleId = dto.TargetId }); }
private object InsertConnection(ModuleConnectionDto connectionDto) { if (connectionDto.SourceId <= 0 || connectionDto.TargetId <= 0) { return(false); } if (!_moduleConnectionService.Insert(connectionDto)) { return(false); } _audioEngine.AddConnection(connectionDto.Id); return(connectionDto); }
private dynamic UpdateConnection(ModuleConnectionDto connectionDto) { var existing = _moduleConnectionService.GetById(connectionDto.Id); if (existing == null) { return(false); } _audioEngine.RemoveConnection(connectionDto.Id); if (!_moduleConnectionService.Update(connectionDto)) { return(false); } _audioEngine.AddConnection(connectionDto.Id); return(connectionDto); }
/// <inheritdoc /> public bool Insert(ModuleConnectionDto dto) { using var dbContext = _dbContextFactory.Create <EngineDbContext>(); var connection = dbContext.ModuleConnections.SingleOrDefault(c => c.SourceModuleId == dto.SourceId && c.TargetModuleId == dto.TargetId); if (connection != null) { return(false); } connection = GetModuleConnection(dto); dbContext.ModuleConnections.Add(connection); if (dbContext.SaveChanges() > 0) { dto.Id = connection.Id; return(true); } return(false); }
public async Task InsertValidDto() { var audioEngineMock = new Mock <IAudioEngine>(); var serviceMock = new Mock <IModuleConnectionService>(); audioEngineMock.Setup(x => x.AddConnection(It.IsAny <long>())).Verifiable(); serviceMock.Setup(x => x.Insert(It.IsAny <ModuleConnectionDto>())).Returns(true); var processor = new ModuleConnectionsProcessor(audioEngineMock.Object, serviceMock.Object); var dto = new ModuleConnectionDto { SourceId = 1, SourceConnectorName = "Source", TargetId = 2, TargetConnectorName = "Target" }; var result = await processor.ProcessAsync("insert", dto).ConfigureAwait(false); Assert.NotNull(result); Assert.True(result.IsSuccess); audioEngineMock.Verify(x => x.AddConnection(It.IsAny <long>())); }
/// <summary> /// Updates a connection and returns the validated/saved DTO. /// </summary> public async Task <ServiceResult <ModuleConnectionDto> > UpdateAsync(ModuleConnectionDto connectionDto) { var response = await _apiClient.SendMessageAsync(ResourceName, "update", connectionDto).ConfigureAwait(false); return(new ServiceResult <ModuleConnectionDto>(response)); }