Exemplo n.º 1
0
        public void AcquireAsyncShouldThrowInvalidOperationExceptionIfPackageIsNull()
        {
            var db = DbInfrastructure.GetDatabase();

            var mockUserManager = this.GetUserManagerMock();

            mockUserManager
            .Setup(m => m.FindByIdAsync(It.IsAny <string>()))
            .Returns((string id) => db.Users.SingleOrDefaultAsync(u => u.Id == id));

            var receiptService = new Mock <IReceiptService>().Object;

            var packageService = new PackageService(db, receiptService, mockUserManager.Object);

            Func <Task> func = async() => await packageService.AcquireAsync(5);

            func.Should().Throw <InvalidOperationException>();
        }
Exemplo n.º 2
0
        public async Task AcquireAsyncShouldMarkGivenPackageAsAcquired()
        {
            var db = DbInfrastructure.GetDatabase();

            var mockUserManager = this.GetUserManagerMock();

            mockUserManager
            .Setup(m => m.FindByIdAsync(It.IsAny <string>()))
            .Returns((string id) => db.Users.SingleOrDefaultAsync(u => u.Id == id));

            var receiptService = new Mock <IReceiptService>().Object;

            var packageService = new PackageService(db, receiptService, mockUserManager.Object);

            var package = new Package
            {
                Description     = Description,
                ShippingAddress = ShippingAddress,
                Weight          = Weight
            };

            await db.AddAsync(package);

            await db.SaveChangesAsync();

            var createdPackage = await db.Packages.FirstOrDefaultAsync();

            await packageService.AcquireAsync(createdPackage.Id);

            var actualPackage = await db.Packages.FirstOrDefaultAsync();

            actualPackage
            .Status
            .Should()
            .Be(Status.Acquired);
        }