Exemplo n.º 1
0
        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);
            });
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
        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);
            });
        }
Exemplo n.º 4
0
        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);
        }