Exemplo n.º 1
0
        public async Task CreateBar_Throws_When_NameIsNull()
        {
            //Arrange

            var options = Utils.GetOptions(nameof(CreateBar_Throws_When_NameIsNull));

            var bar = new Bar
            {
                Id   = Guid.NewGuid(),
                Name = "Cosmos"
            };

            var barDTO = new BarDTO
            {
                Id   = Guid.NewGuid(),
                Name = null
            };

            using (var arranegContext = new CMContext(options))
            {
                await arranegContext.Bars.AddAsync(bar);

                await arranegContext.SaveChangesAsync();
            }

            //Act,Assert
            using (var assertContext = new CMContext(options))
            {
                var sut = new BarServices(assertContext);

                await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => sut.CreateBar(barDTO));
            }
        }
Exemplo n.º 2
0
        public async Task CreateBar_Return_Correct_When_Params_AreValid()
        {
            //Arrange

            var options = Utils.GetOptions(nameof(CreateBar_Return_Correct_When_Params_AreValid));


            var country = new Country {
                Id = Guid.Parse("295afbfe-5410-49db-b5b1-161b1ce8fd3c"), Name = "USA"
            };
            var bar = new BarDTO
            {
                Id          = Guid.NewGuid(),
                Name        = "Cosmos",
                CountryId   = country.Id,
                CountryName = country.Name
            };

            using (var arrangeContext = new CMContext(options))
            {
                await arrangeContext.Countries.AddAsync(country);

                await arrangeContext.SaveChangesAsync();
            }

            //Act,Assert
            using (var assertContext = new CMContext(options))
            {
                var sut    = new BarServices(assertContext);
                var result = await sut.CreateBar(bar);


                Assert.AreEqual(1, assertContext.Bars.Count());
                Assert.AreEqual(bar.Name, result.Name);
                Assert.IsInstanceOfType(result, typeof(BarDTO));
            }
        }