private void SetupPmodes() { ReceivingBasePmode = new ReceivingBasePmode() { Name = "test1", Type = PmodeType.Receiving }; SendingBasePmode = new SendingBasePmode() { Name = "test2", Type = PmodeType.Sending }; ReceivingPmodes = new List <ReceivingBasePmode> { ReceivingBasePmode }; SendingPmodes = new List <SendingBasePmode> { SendingBasePmode }; Source.GetReceivingNames().Returns(ReceivingPmodes.Select(pmode => pmode.Name)); Source.GetReceivingByName(Arg.Is(ReceivingBasePmode.Name)).Returns(ReceivingBasePmode); Source.GetSendingNames().Returns(SendingPmodes.Select(pmode => pmode.Name)); Source.GetSendingByName(Arg.Is(SendingBasePmode.Name)).Returns(SendingBasePmode); }
public async Task Throws_Exception_When_Pmode_Already_Exists() { // Setup var test = Setup(); var pmode = new ReceivingBasePmode() { Name = ReceivingBasePmode.Name }; await Assert.ThrowsAsync <AlreadyExistsException>(() => test.Service.CreateReceiving(pmode)); }
public async Task Throws_Exception_When_A_Pmode_With_The_New_Name_Already_Exists() { // Setup var test = Setup(); var newPmode = new ReceivingBasePmode() { Name = ReceivingBasePmode.Name }; // Act await Assert.ThrowsAsync <AlreadyExistsException>(() => test.Service.UpdateReceiving(newPmode, "NEW")); }
/// <summary> /// Create a receiving pmode /// </summary> /// <param name="basePmode">The pmode to create</param> /// <returns></returns> /// <exception cref="Eu.EDelivery.AS4.Fe.AlreadyExistsException"> /// Exception thrown when a pmode with the supplied name /// already exists /// </exception> public async Task CreateReceiving(ReceivingBasePmode basePmode) { EnsureArg.IsNotNull(basePmode, nameof(basePmode)); var exists = await source.GetReceivingByName(basePmode.Name); if (exists != null) { throw new AlreadyExistsException($"BasePmode with name {basePmode.Name} already exists."); } ValidateReceivingPmode(basePmode); await source.CreateReceiving(basePmode); }
private void ValidateReceivingPmode(ReceivingBasePmode sendingPmode) { if (disableValidation) { return; } var result = ReceivingProcessingModeValidator.Instance.Validate(sendingPmode.Pmode); if (!result.IsValid) { throw new InvalidPModeException("Invalid PMode", result); } }
/// <summary> /// Creates the receiving. /// </summary> /// <param name="basePmode">The base pmode.</param> /// <returns></returns> public async Task CreateReceiving(ReceivingBasePmode basePmode) { string fileName = FilterOutInvalidFileNameChars(basePmode.Name); string pmodeFile = Path.Combine(_settings.Value.ReceivingPmodeFolder, fileName + ".xml"); if (File.Exists(pmodeFile)) { pmodeFile = Path.Combine(_settings.Value.ReceivingPmodeFolder, fileName + "-" + Guid.NewGuid() + ".xml"); } string pmodeString = await AS4XmlSerializer.ToStringAsync(basePmode.Pmode); File.WriteAllText(pmodeFile, pmodeString); }
public async Task Updates_Existing() { // Setup var test = Setup(); var newPmode = new ReceivingBasePmode() { Name = "NEW" }; // Act await test.Service.UpdateReceiving(newPmode, ReceivingBasePmode.Name); // Assert await test.Source.UpdateReceiving(Arg.Is <ReceivingBasePmode>(x => x.Name == "NEW"), Arg.Is(ReceivingBasePmode.Name)); }
public async Task Calls_Source_SaveReceiving() { // Setup var test = Setup(); var pmode = new ReceivingBasePmode() { Name = "newPmode" }; // Act await test.Service.CreateReceiving(pmode); // Assert await test.Source.Received().CreateReceiving(Arg.Is <ReceivingBasePmode>(x => x.Name == "newPmode")); }
/// <summary> /// Update receiving pmode /// </summary> /// <param name="basePmode">The base pmode.</param> /// <param name="originalName">Name of the original.</param> /// <returns></returns> /// <exception cref="Eu.EDelivery.AS4.Fe.AlreadyExistsException"> /// Exception thrown when a pmode with the supplied name /// already exists. /// </exception> public async Task UpdateReceiving(ReceivingBasePmode basePmode, string originalName) { EnsureArg.IsNotNull(basePmode, nameof(basePmode)); EnsureArg.IsNotNullOrEmpty(originalName, nameof(originalName)); if (basePmode.Name != originalName) { var newExists = await GetReceivingByName(basePmode.Name); if (newExists != null) { throw new AlreadyExistsException($"BasePmode with {originalName} already exists"); } } ValidateReceivingPmode(basePmode); await source.UpdateReceiving(basePmode, originalName); }
/// <summary> /// Updates the receiving. /// </summary> /// <param name="basePmode">The base pmode.</param> /// <param name="originalName">Name of the original.</param> /// <returns></returns> public async Task UpdateReceiving(ReceivingBasePmode basePmode, string originalName) { await CreateReceiving(basePmode); File.Delete(_config.GetFileLocationForReceivingPMode(originalName)); }
public async Task UpdateReceiving([FromBody] ReceivingBasePmode basePmode, string originalName) { await pmodeService.UpdateReceiving(basePmode, originalName); }
public async Task CreateReceiving([FromBody] ReceivingBasePmode basePmode) { await pmodeService.CreateReceiving(basePmode); }