コード例 #1
0
        public async Task Return_CorrectIcbSensor_WhenFoundId()
        {
            // Arrange
            contextOptions = new DbContextOptionsBuilder <SmartDormitoryContext>()
                             .UseInMemoryDatabase(databaseName: "Return_CorrectUser_WhenFoundId")
                             .Options;
            string id = Guid.NewGuid().ToString();

            using (var assertContext = new SmartDormitoryContext(contextOptions))
            {
                await assertContext.IcbSensors.AddAsync(new IcbSensor
                {
                    Id = id,
                    PollingInterval = 10,
                    Description     = "Some description",
                    Tag             = "Some tag",
                    MinRangeValue   = 10,
                    MaxRangeValue   = 20
                });

                await assertContext.SaveChangesAsync();
            }

            // Act && Asert
            using (var assertContext = new SmartDormitoryContext(contextOptions))
            {
                var measureTypeServiceMock = new Mock <IMeasureTypeService>();
                var sut    = new IcbSensorsService(assertContext, measureTypeServiceMock.Object);
                var result = await sut.GetById(id);

                Assert.IsNotNull(result);
                Assert.IsTrue(id.Equals(result.Id));
            }
        }
コード例 #2
0
        public async Task ThrowArugmentException_WhenPassedInvalidGuid()
        {
            // Arrange
            var contextMock            = new Mock <SmartDormitoryContext>();
            var measureTypeServiceMock = new Mock <IMeasureTypeService>();

            var sut = new IcbSensorsService(contextMock.Object, measureTypeServiceMock.Object);

            // Act & Assert
            await Assert.ThrowsExceptionAsync <ArgumentException>(
                () => sut.GetById("invalidGuid"), "Parameter sensorId is not a valid GUID!");
        }
コード例 #3
0
        public async Task ThrowArugmentNullException_WhenPassedNullSensorId()
        {
            // Arrange
            var contextMock            = new Mock <SmartDormitoryContext>();
            var measureTypeServiceMock = new Mock <IMeasureTypeService>();

            var sut = new IcbSensorsService(contextMock.Object, measureTypeServiceMock.Object);

            // Act & Assert
            await Assert.ThrowsExceptionAsync <ArgumentNullException>(
                () => sut.GetById(null), "Parameter sensorId cannot be null!");
        }
コード例 #4
0
        public async Task Return_CorrectType_WhenFoundId()
        {
            // Arrange
            contextOptions = new DbContextOptionsBuilder <SmartDormitoryContext>()
                             .UseInMemoryDatabase(databaseName: "Return_CorrectType_WhenFoundId")
                             .Options;
            string id = Guid.NewGuid().ToString();

            using (var assertContext = new SmartDormitoryContext(contextOptions))
            {
                await assertContext.IcbSensors.AddRangeAsync(new IcbSensor
                {
                    Id = id,
                    PollingInterval = 10,
                    Description     = "Some description",
                    Tag             = "Some tag",
                    MinRangeValue   = 10,
                    MaxRangeValue   = 20,
                    IsDeleted       = false,
                },
                                                             new IcbSensor
                {
                    Id = "deletedId",
                    PollingInterval = 10,
                    Description     = "Some description",
                    Tag             = "Some tag",
                    MinRangeValue   = 10,
                    MaxRangeValue   = 20,
                    IsDeleted       = true,
                });

                await assertContext.SaveChangesAsync();
            }

            // Act && Asert
            using (var assertContext = new SmartDormitoryContext(contextOptions))
            {
                var measureTypeServiceMock = new Mock <IMeasureTypeService>();
                var sut = new IcbSensorsService(assertContext, measureTypeServiceMock.Object);

                var result = await sut.GetById(id);

                Assert.IsInstanceOfType(result, typeof(IcbSensorCreateServiceModel));
            }
        }
コード例 #5
0
        public async Task Return_Null_When_Id_Is_Not_Found()
        {
            // Arrange
            contextOptions = new DbContextOptionsBuilder <SmartDormitoryContext>()
                             .UseInMemoryDatabase(databaseName: "Return_Null_When_Id_Is_Not_Found")
                             .Options;
            string id = Guid.NewGuid().ToString();;

            // Act && Asert
            using (var assertContext = new SmartDormitoryContext(contextOptions))
            {
                var measureTypeServiceMock = new Mock <IMeasureTypeService>();
                var sut    = new IcbSensorsService(assertContext, measureTypeServiceMock.Object);
                var result = await sut.GetById(id);

                Assert.IsNull(result);
            }
        }