Example #1
0
        public async Task TestAddListingAsyncInputModelNull()
        {
            // Arrange
            var options = BuildDbContextOptions();

            using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureCreated();

                var repository = new ListingRepository(context);

                var service = new ListingService(repository,
                                                 null,
                                                 null,
                                                 null,
                                                 null,
                                                 null);

                Assert.Equal(6, context.Listing.Count());

                // Act
                await service.AddListingAsync(null);
            }

            await using (var context = new ApplicationDbContext(options))
            {
                // Assert
                Assert.Equal(6, context.Listing.Count());

                context.Database.EnsureDeleted();
            }
        }
Example #2
0
        public void TestAddNullObject()
        {
            // Arrange
            var options = BuildDbContextOptions();
            ListingInputModel testObject = null;

            // Act
            using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureCreated();

                var repository = new ListingRepository(context);

                var service = new ListingService(repository, null, null, null, null, null);

                service.AddListingAsync(testObject);
            }

            // Assert
            using (var context = new ApplicationDbContext(options))
            {
                var result = context.Listing.ToList();

                Assert.Equal(6, result.Count);

                context.Database.EnsureDeleted();
            }
        }
        public async Task <IActionResult> Create()
        {
            var listing = await _listingService.AddListingAsync();

            return(Redirect("Edit?listingId=" + listing.Id.ToString()));
        }
Example #4
0
        public async Task TestUpdateListingAsyncSourceNull()
        {
            // Arrange
            var options = BuildDbContextOptions();

            ListingInputModel testInputModel = null;

            var mockRepairJobService = new Mock <IRepairJobService>();

            mockRepairJobService
            .Setup(x => x.MapRepairJobValues(
                       It.IsAny <RepairJobInputModel>(),
                       It.IsAny <RepairJob>()))
            .Verifiable();

            var mockCarService = new Mock <ICarService>();

            mockCarService
            .Setup(x => x.MapCarValues(
                       It.IsAny <CarInputModel>(),
                       It.IsAny <Car>()))
            .Verifiable();

            var mockMediaService = new Mock <IMediaService>();

            mockMediaService
            .Setup(x => x.UpdateMediaCollection(
                       It.IsAny <IEnumerable <string> >(),
                       It.IsAny <Listing>()))
            .Verifiable();

            var mockStatusService = new Mock <IStatusService>();

            using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureCreated();

                var status = context.Status.FirstOrDefault(s => s.Id == 1);

                mockStatusService
                .Setup(x => x.GetStatusByIdAsync(It.IsAny <int>()))
                .ReturnsAsync(status)
                .Verifiable();

                var repository = new ListingRepository(context);

                var service = new ListingService(repository,
                                                 mockRepairJobService.Object,
                                                 mockCarService.Object,
                                                 mockStatusService.Object,
                                                 mockMediaService.Object,
                                                 _mapper);

                Assert.Equal(6, context.Listing.Count());

                // Act
                await service.AddListingAsync(testInputModel);
            }

            await using (var context = new ApplicationDbContext(options))
            {
                // Assert
                var listings = context.Listing.ToList();

                Assert.Equal(6, listings.Count);

                mockRepairJobService
                .Verify(x => x.MapRepairJobValues(
                            It.IsAny <RepairJobInputModel>(),
                            It.IsAny <RepairJob>()),
                        Times.Never);

                mockCarService
                .Verify(x => x.MapCarValues(
                            It.IsAny <CarInputModel>(),
                            It.IsAny <Car>()),
                        Times.Never);

                mockStatusService
                .Verify(x => x.GetStatusByIdAsync(It.IsAny <int>()),
                        Times.Never);

                mockMediaService
                .Verify(x => x.UpdateMediaCollection(
                            It.IsAny <IEnumerable <string> >(),
                            It.IsAny <Listing>()),
                        Times.Never);

                context.Database.EnsureDeleted();
            }
        }