public async Task Should_Error_Create_Valid_Model()
        {
            var dbContext           = GetDbContext(GetCurrentMethod());
            var serviceProviderMock = GetServiceProviderMock();

            var service = new AbsensiService(dbContext, serviceProviderMock.Object);
            var model   = GetNewModel();

            var result = await service.Create(model);

            await Assert.ThrowsAsync <Exception>(() => service.Delete(model.Id + 1));
        }
        public async Task Should_Success_Create_Valid_Model()
        {
            var dbContext           = GetDbContext(GetCurrentMethod());
            var serviceProviderMock = GetServiceProviderMock();

            var service = new AbsensiService(dbContext, serviceProviderMock.Object);
            var model   = GetNewModel();

            var result = await service.Create(model);

            Assert.NotEqual(result, 0);
        }
Exemple #3
0
        public async Task Should_Success_Update_Data()
        {
            var AbsensiServiceMock = new Mock <IAbsensiService>();

            AbsensiServiceMock.Setup(AbsensiService => AbsensiService.Create(It.IsAny <Absensi>()))
            .ReturnsAsync(1);

            var validateServiceMock = new Mock <IValidateService>();

            validateServiceMock.Setup(validateService => validateService.Validate(It.IsAny <Absensi>()))
            .Verifiable();

            var serviceProviderMock = GetServiceProviderMock(AbsensiServiceMock.Object, validateServiceMock.Object);

            var controller = GetController(serviceProviderMock.Object);
            var response   = await controller.Put(new Absensi().Id, new Absensi());

            Assert.Equal((int)HttpStatusCode.NoContent, GetStatusCode(response));
        }
Exemple #4
0
        public async Task Should_Success_Post_Invalid_Data()
        {
            var AbsensiServiceMock = new Mock <IAbsensiService>();

            AbsensiServiceMock.Setup(AbsensiService => AbsensiService.Create(It.IsAny <Absensi>()))
            .ReturnsAsync(1);

            var validateServiceMock = new Mock <IValidateService>();

            validateServiceMock.Setup(validateService => validateService.Validate(It.IsAny <Absensi>()))
            .Throws(GetServiceValidationException());

            var serviceProviderMock = GetServiceProviderMock(AbsensiServiceMock.Object, validateServiceMock.Object);

            var controller = GetController(serviceProviderMock.Object);
            var response   = await controller.Post(new Absensi());

            Assert.Equal((int)HttpStatusCode.BadRequest, GetStatusCode(response));
        }