public async Task CreateCorrect_Ingredient() { //Arrange var options = TestUtilities.GetOptions(nameof(CreateCorrect_Ingredient)); var mapper = new Mock <IDtoMapper <Ingredient, IngredientDto> >(); var mockDateTimeProvider = new Mock <IDateTimeProvider>(); var ingredientDto = new IngredientDto { Name = "Cola" }; mapper.Setup(x => x.MapDto(It.IsAny <Ingredient>())).Returns(ingredientDto); using (var assertContext = new CocktailMagicianContext(options)) { //Act & Assert var sut = new IngredientService(assertContext, mapper.Object, mockDateTimeProvider.Object); var result = await sut.CreateIngredientAsync(ingredientDto); Assert.IsInstanceOfType(result, typeof(IngredientDto)); Assert.AreEqual(0, result.Id); Assert.AreEqual("Cola", result.Name); } }
public async Task CorrectlyCreateIngredient() { //Arrange var options = TestUtilities.GetOptions(nameof(CorrectlyCreateIngredient)); var mapperMock = new Mock <IDtoMapper <Ingredient, IngredientDto> >(); var testGuid = Guid.NewGuid(); var entityDto = new IngredientDto { Id = testGuid, Name = "djodjan", }; var ingredientDto = new IngredientDto { Id = testGuid, Name = "djodjan", }; mapperMock.Setup(x => x.MapFrom(It.IsAny <Ingredient>())).Returns(ingredientDto); using (var assertContext = new CWContext(options)) { //Act & Assert var sut = new IngredientService(assertContext, mapperMock.Object); var result = await sut.CreateIngredientAsync(entityDto); Assert.IsInstanceOfType(result, typeof(IngredientDto)); Assert.AreEqual("djodjan", result.Name); Assert.AreEqual(entityDto.Name, result.Name); } }
public async Task ReturnInstanceOfTypeIngredientDto() { //Arrange var options = TestUtilities.GetOptions(nameof(ReturnInstanceOfTypeIngredientDto)); var mapperMock = new Mock <IDtoMapper <Ingredient, IngredientDto> >(); using (var assertContext = new CWContext(options)) { //Act & Assert var sut = new IngredientService(assertContext, mapperMock.Object); var result = await sut.CreateIngredientAsync("djodjan"); Assert.IsInstanceOfType(result, typeof(Ingredient)); Assert.AreEqual("djodjan", result.Name); } }
public async Task CreatesPrimaryIngredient() { string ingredientName = "Ingredient"; byte type = 1; var options = TestUtilities.GetOptions(nameof(CreatesPrimaryIngredient)); using (var actContext = new CocktailDatabaseContext(options)) { var sut = new IngredientService(actContext); await sut.CreateIngredientAsync(ingredientName, type); } using (var assertContext = new CocktailDatabaseContext(options)) { var ingredient = assertContext.Ingredients.First(); Assert.IsNotNull(ingredient); Assert.AreEqual(type, ingredient.Primary); Assert.AreEqual(ingredientName.ToLower(), ingredient.Name); } }
public async Task CreateIngredient_WhenParamsAreValid() { //Arrange var mockDatetimeProvider = new Mock <IDateTimeProvider>(); var mockMapper = new Mock <IIngredientMapper>(); mockMapper.Setup(i => i.MapToIngredient(It.IsAny <IngredientDTO>())) .Returns <IngredientDTO>(i => new Ingredient { Name = i.Name, ImageData = i.ImageData, ImageSource = i.ImageSource }); var mockCocktailMapper = new Mock <ICocktailMapper>(); var options = Utils.GetOptions(nameof(CreateIngredient_WhenParamsAreValid)); var ingredientDTO = new IngredientDTO { Name = "Black Pepper", ImageData = new byte[] { }, ImageSource = "~/Testimage/pqt-ozer-premium.jpg" }; string imageBase64Data = Convert.ToBase64String(ingredientDTO.ImageData); ingredientDTO.ImageSource = string.Format("data:image/jpg;base64,{0}", imageBase64Data); Utils.GetInMemoryDataBase(options); //Act & Assert using (var assertContext = new CocktailMagicianContext(options)) { var sut = new IngredientService(mockDatetimeProvider.Object, mockMapper.Object, mockCocktailMapper.Object, assertContext); var result = await sut.CreateIngredientAsync(ingredientDTO); Assert.IsInstanceOfType(result, typeof(IngredientDTO)); } }