public void UpdateListing()
        {
            using var _context = TestContext.GetContext();
            var _mapper = TestMapper.GetTestMapper();
            var _studioListingService = new StudioListingService(_context, _mapper);

            var update = new CreateUpdateStudioDto
            {
                Name        = "Basil's Place", // updated name
                Description = "We are the best studio",
                IsBooked    = false,
                Rate        = 20
            };

            var response = _studioListingService.UpdateListing(2, update);

            Assert.IsType <ServiceResponse <StudioListingDto> >(response);
            Assert.IsType <StudioListingDto>(response.Data);
            Assert.Equal("Basil's Place", response.Data.Name);
            Assert.Equal("We are the best studio", response.Data.Description);
            Assert.False(response.Data.IsBooked);
            Assert.Equal(20, response.Data.Rate);
            Assert.NotEqual("The Hive", response.Data.Name);
            Assert.True(response.IsSuccess);
        }
Beispiel #2
0
        public void Add_OK()
        {
            Ctx = new TestPlatformDBEntities();
            Ctx.Tests.Add(TestMapper.MapBizToDal(_test));

            Ctx.Users.Add(new User
            {
                Id       = 0,
                Username = "******",
                Password = "******"
            });

            AdministratedTestRepository repo = new AdministratedTestRepository(Ctx);
            AdministratedTestService    administratedTestService = new AdministratedTestService(repo);
            var adTest = administratedTestService.AdministratedTest_Builder(TestMapper.MapDalToBiz(Ctx.Tests.Find(1)), "Daniele Tulli");

            administratedTestService.Add(adTest);

            var ad = repo.GetAdministratedTestById(1);

            ad.Should()
            .NotBeNull()
            .And
            .Be(ad.Id == 1);
        }
        public async Task ChangePhoneAsync_ShouldBeOkObjectResult()
        {
            // Arrange
            var user = TestData.FileStorage.GetUsers().First();

            TestMock.UserService.Setup(userService => userService.GetUserAsync(It.IsAny <ClaimsPrincipal>())).ReturnsAsync(user).Verifiable();

            TestMock.UserService.Setup(userService => userService.UpdatePhoneNumberAsync(It.IsAny <User>(), It.IsAny <string>()))
            .ReturnsAsync(IdentityResult.Success)
            .Verifiable();

            var controller = new PhoneController(TestMock.UserService.Object, TestMapper);

            var request = new ChangePhoneRequest
            {
                Number = user.PhoneNumber
            };

            // Act
            var result = await controller.ChangePhoneAsync(request);

            // Assert
            result.Should().BeOfType <OkObjectResult>();
            result.As <OkObjectResult>().Value.Should().BeEquivalentTo(TestMapper.Map <PhoneDto>(user));
            TestMock.UserService.Verify(userService => userService.GetUserAsync(It.IsAny <ClaimsPrincipal>()), Times.Once);
            TestMock.UserService.Verify(userService => userService.UpdatePhoneNumberAsync(It.IsAny <User>(), It.IsAny <string>()), Times.Once);
        }
Beispiel #4
0
    private static ArticleService CreateTestee(Mock <IArticleAction> articleActionMock, InMemoryDbContext context)
    {
        var mapper = TestMapper.Create();
        var testee = new ArticleService(articleActionMock.Object, context, mapper, new SimpleCrudHelper(context, mapper));

        return(testee);
    }
Beispiel #5
0
        public TestBusiness GetTestById(int testId)
        {
            Repo = new TestRepository();

            Test test = null;

            try
            {
                test = Repo.GetTest(testId);
            }
            catch (NullReferenceException ex)
            {
                throw;
            }
            catch (InvalidOperationException ex)
            {
                //TODO
            }
            catch (Exception ex)
            {
                //TODO
            }

            TestBusiness testBusiness = TestMapper.MapDalToBiz(test);

            return(testBusiness);
        }
Beispiel #6
0
            public void IgnoringAnEnumerableDoesNotCauseError()
            {
                var mapper = new TestMapper <Foo>();

                mapper.Map(m => m.List).Ignore();
                Assert.AreEqual(2, mapper.Properties.Count);
            }
 public void AssertThatMapperIsCalledWhenMapperSetOnDatabase()
 {
     var mapper = new TestMapper();
     Database.Mapper = mapper;
     var users = Database.Fetch<UserFieldDecorated>();
     Assert.AreEqual(true, mapper.IsGetFromDbConverter);
 }
Beispiel #8
0
        [HttpGet, AllowAnonymous] //AllowAnonymous允许控制器匿名访问
        public dynamic List(string name = null)
        {
            TestMapper mapper = new TestMapper();
            var        dict   = mapper.selectTest(name);

            return(Success(dict));
        }
Beispiel #9
0
        [HttpGet, AllowAnonymous] //AllowAnonymous允许控制器匿名访问
        public dynamic Add(string name = null)
        {
            TestMapper mapper = new TestMapper();
            var        dict   = mapper.Add(name);

            return(Success("操作成功"));
        }
Beispiel #10
0
 public void CsvMapping_Factory_CanCreateMapper()
 {
     var mapper = new TestMapper();
     var data   = "value1,123".AsSpan();
     var index  = new [] { 0, 6, 7, 3 };
     //var entity = mapper.Map(data, ref index);
 }
Beispiel #11
0
        public Business.Entities.Test GetTest(int testId)
        {
            var dbContext = _context.GetInstance();
            var test      = dbContext.Tests.FirstOrDefault(x => x.Id == testId);

            return(TestMapper.MapDalToEntity(test));
        }
Beispiel #12
0
    private static ArticleService CreateTestee(EfCoreContext context)
    {
        var mapper = TestMapper.Create();
        var testee = new ArticleService(new ArticleAction(new ArticleDbAccess(context), mapper), context, mapper, new SimpleCrudHelper(context, mapper));

        return(testee);
    }
Beispiel #13
0
            public void DoesNotMapPropertyWhenCanMapIsFalse()
            {
                var mapper = new TestMapper <Foo>();
                Func <Type, PropertyInfo, bool> canMap = (t, p) => ReflectionHelper.IsSimpleType(p.PropertyType);

                mapper.TestProtected().RunMethod("AutoMap", canMap);
                Assert.Equal(1, mapper.Properties.Count);
            }
Beispiel #14
0
 public ActionResult AddTest(TestModel model)
 {
     test.UserId = UserId;
     test.URL    = _service.GenerateGuid();
     test.Date   = DateTime.Now;
     _service.AddNewTest(TestMapper.MapDalToBiz(test));
     return(View("Index"));
 }
Beispiel #15
0
            public void IgnoringAnEnumerableDoesNotCauseError()
            {
                var mapper = new TestMapper <Foo>();

                mapper.Map(m => m.List).Ignore();
                mapper.TestProtected().RunMethod("AutoMap");
                Assert.Equal(2, mapper.Properties.Count);
            }
Beispiel #16
0
    public void GetAllArticles()
    {
        var articleDbAccessMock = new Mock <IArticleDbAccess>();
        var testee = new ArticleAction(articleDbAccessMock.Object, TestMapper.Create());

        testee.GetAllArticles();

        articleDbAccessMock.Verify(x => x.GetArticles(), Times.Once);
    }
Beispiel #17
0
    public void GetAllIngredients()
    {
        var ingredientDbAccessMock = new Mock <IIngredientDbAccess>();
        var testee = new IngredientAction(ingredientDbAccessMock.Object, TestMapper.Create());

        testee.GetAllIngredients();

        ingredientDbAccessMock.Verify(x => x.GetIngredients(), Times.Once);
    }
Beispiel #18
0
        public void AssertThatMapperIsCalledWhenMapperSetOnDatabase()
        {
            var mapper = new TestMapper();

            Database.Mapper = mapper;
            var users = Database.Fetch <UserFieldDecorated>();

            Assert.AreEqual(true, mapper.IsGetFromDbConverter);
        }
        public void SimpleMapWithContext()
        {
            var mapper = new TestMapper();

            var result = mapper.Map(new Source());

            Assert.That(result.Foo, Is.EqualTo("Foo value"));
            Assert.That(result.Bar, Is.EqualTo(11));
        }
Beispiel #20
0
        public void AddTest(ref Business.Entities.Test test)
        {
            var dbContext = _context.GetInstance();
            var testToAdd = TestMapper.MapEntityToDal(test);

            dbContext.Tests.Add(testToAdd);
            dbContext.SaveChanges();
            test = TestMapper.MapDalToEntity(testToAdd);
        }
Beispiel #21
0
        public async Task<IEnumerable<VMItem>> GetVMListAsync(string name)
        {
            var command = new PSCommand { ScriptCommand = String.Format("Get-Service -ComputerName {0}", name) };
            
            var objects = await psProvider.ExecuteAsync<PSObject>(command);

            var mapper = new TestMapper();
            return objects.Select(mapper.Map);
        }
Beispiel #22
0
    public void CreateArticle()
    {
        var newArticleDto       = new NewArticleDto("Cheese", new ExistingArticleGroupDto(3, "Diary"), true);
        var articleDbAccessMock = new Mock <IArticleDbAccess>();
        var testee = new ArticleAction(articleDbAccessMock.Object, TestMapper.Create());

        testee.CreateArticle(newArticleDto);

        articleDbAccessMock.Verify(x => x.AddArticle(It.Is <Article>(a => a.Name == "Cheese")), Times.Once);
    }
Beispiel #23
0
        public void UpdateTest(ref Business.Entities.Test test)
        {
            var dbContext  = _context.GetInstance();
            var newTest    = TestMapper.MapEntityToDal(test);
            var testFromDb = dbContext.Tests.FirstOrDefault(x => x.Id == newTest.Id);

            testFromDb = (Test)UpdateEntity(testFromDb, newTest);
            dbContext.SaveChanges();
            test = TestMapper.MapDalToEntity(testFromDb);
        }
Beispiel #24
0
    public void CreateUnit()
    {
        using var context = new InMemoryDbContext();
        var testee     = new UnitService(new SimpleCrudHelper(context, TestMapper.Create()));
        var newUnitDto = new NewUnitDto("Piece");

        testee.CreateUnit(newUnitDto);

        context.Units.Should().Contain(x => x.Name == "Piece");
    }
Beispiel #25
0
    public void CreateMealType()
    {
        using var context = new InMemoryDbContext();
        var testee         = new MealTypeService(new SimpleCrudHelper(context, TestMapper.Create()));
        var newMealTypeDto = new NewMealTypeDto("Lunch");

        testee.CreateMealType(newMealTypeDto);

        context.MealTypes.Should().Contain(x => x.Name == "Lunch");
    }
Beispiel #26
0
 public void AddNewTest(TestBusiness test)
 {
     using (TestRepository _repo = new TestRepository())
     {
         if (string.IsNullOrWhiteSpace(test.URL))
         {
             throw new Exception("Test not saved");
         }
         _repo.SaveTest(TestMapper.MapBizToDal(test));
     }
 }
Beispiel #27
0
    public void GetAllArticleGroups()
    {
        using var context = new InMemoryDbContext();
        context.ArticleGroups.Add(new ArticleGroup("Vegetables"));
        context.ArticleGroups.Add(new ArticleGroup("Dairy"));
        context.SaveChanges();
        var testee = new ArticleGroupService(new SimpleCrudHelper(context, TestMapper.Create()));

        var results = testee.GetAllArticleGroups();

        results.Should().Contain(x => x.Name == "Vegetables").And.Contain(x => x.Name == "Dairy");
    }
Beispiel #28
0
    public void GetAllMealTypes()
    {
        using var context = new InMemoryDbContext();
        context.MealTypes.Add(new MealType("Lunch", 1));
        context.MealTypes.Add(new MealType("Breakfast", 2));
        context.SaveChanges();
        var testee = new MealTypeService(new SimpleCrudHelper(context, TestMapper.Create()));

        var results = testee.GetAllMealTypes();

        results.Should().Contain(x => x.Name == "Lunch").And.Contain(x => x.Name == "Breakfast");
    }
Beispiel #29
0
        [HttpGet, AllowAnonymous] //AllowAnonymous允许控制器匿名访问
        public dynamic Update(int id = 0, string name = null)
        {
            var test = new Test()
            {
                Id   = id,
                Name = name
            };
            TestMapper mapper = new TestMapper();

            mapper.Update(test);
            return(Success("操作成功"));
        }
        public void ShouldDeleteClient()
        {
            using var _context = TestContext.GetContext();
            var _mapper        = TestMapper.GetTestMapper();
            var _clientService = new ClientService(_mapper, _context);

            var response = _clientService.DeleteClient("id1");

            Assert.IsType <ServiceResponse <bool> >(response);
            Assert.True(response.IsSuccess);
            Assert.Equal(1, _context.Clients.Count());
        }
Beispiel #31
0
        /// <summary>
        /// Select a colleciton of items from the data source
        /// </summary>
        /// <param name="criteria">Criteria for querying the data source</param>
        /// <returns>Collection of Item</returns>
        public override IEnumerable <Test> SelectCollection(CommandCriteria criteria)
        {
            IEnumerable <Test> result = null;

            SR.Admittance admittance = this.GetItemCollection(criteria).SingleOrDefault();
            if (admittance != null)
            {
                result = new TestMapper().MapCollection(admittance.Tests);
            }

            return(result);
        }
        public void ShouldGetAllClients()
        {
            using var _context = TestContext.GetContext();
            var _mapper        = TestMapper.GetTestMapper();
            var _clientService = new ClientService(_mapper, _context);

            var response = _clientService.GetAllClients();

            Assert.IsType <ServiceResponse <List <HomeBooth.Services.DTO.ApplicationUserDto> > >(response);
            Assert.True(response.IsSuccess);
            Assert.Equal(2, _context.Clients.Count());
        }
        public GetSubmittedMovementsHandlerTests()
        {
            SystemTime.Freeze(new DateTime(2015, 1, 1));

            var repository = A.Fake<IMovementRepository>();
            var movements = new[]
            {
                GetMovement(1),
                GetMovement(2),
                GetMovement(3),
                GetMovement(4),
                GetMovement(5),
            };

            A.CallTo(() => repository.GetMovementsByStatus(NotificationId, MovementStatus.Submitted))
                .Returns(movements);

            var testMapper = new TestMapper();
            testMapper.AddMapper(new SubmittedMovementMap());
            handler = new GetSubmittedMovementsHandler(repository, testMapper);
        }