public void MerchantAggregate_AddDevice_DuplicateDevice_ErrorThrown() { MerchantAggregate aggregate = MerchantAggregate.Create(TestData.MerchantId); aggregate.Create(TestData.EstateId, TestData.MerchantName, TestData.DateMerchantCreated); aggregate.AddDevice(TestData.DeviceId, TestData.DeviceIdentifier); Should.Throw <InvalidOperationException>(() => { aggregate.AddDevice(TestData.DeviceId, TestData.DeviceIdentifier); }); }
/// <summary> /// Adds the device to merchant. /// </summary> /// <param name="estateId">The estate identifier.</param> /// <param name="merchantId">The merchant identifier.</param> /// <param name="deviceId">The device identifier.</param> /// <param name="deviceIdentifier">The device identifier.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> public async Task AddDeviceToMerchant(Guid estateId, Guid merchantId, Guid deviceId, String deviceIdentifier, CancellationToken cancellationToken) { MerchantAggregate merchantAggregate = await this.MerchantAggregateRepository.GetLatestVersion(merchantId, cancellationToken); // Check merchant has been created if (merchantAggregate.IsCreated == false) { throw new InvalidOperationException($"Merchant Id {merchantId} has not been created"); } // Estate Id is a valid estate EstateAggregate estateAggregate = await this.EstateAggregateRepository.GetLatestVersion(estateId, cancellationToken); if (estateAggregate.IsCreated == false) { throw new InvalidOperationException($"Estate Id {estateId} has not been created"); } merchantAggregate.AddDevice(deviceId, deviceIdentifier); await this.MerchantAggregateRepository.SaveChanges(merchantAggregate, cancellationToken); }
public void MerchantAggregate_AddDevice_DeviceIdentifierInvalid_ErrorThrown(String deviceIdentifier) { MerchantAggregate aggregate = MerchantAggregate.Create(TestData.MerchantId); aggregate.Create(TestData.EstateId, TestData.MerchantName, TestData.DateMerchantCreated); Should.Throw <ArgumentNullException>(() => { aggregate.AddDevice(TestData.DeviceId, deviceIdentifier); }); }
public void MerchantAggregate_AddDevice_DeviceAdded() { MerchantAggregate aggregate = MerchantAggregate.Create(TestData.MerchantId); aggregate.Create(TestData.EstateId, TestData.MerchantName, TestData.DateMerchantCreated); aggregate.AddDevice(TestData.DeviceId, TestData.DeviceIdentifier); Merchant merchantModel = aggregate.GetMerchant(); merchantModel.Devices.ShouldHaveSingleItem(); merchantModel.Devices.Single().Key.ShouldBe(TestData.DeviceId); merchantModel.Devices.Single().Value.ShouldBe(TestData.DeviceIdentifier); }