Bit of a code snippet of a project I am working on… kinda 2 at this point.
--[[
Runs unit tests for the InjectEnvironmentVariables method to simulate a DataStore error.
--]]
NexusUnitTesting:RegisterUnitTest("InjectEnvironmentVariables_DataStoreSimulatedFailure",function(UnitTest)
local ProperErrorWarned = false
--Create the fake DataStore.
local FakeDataStoreInjector = DependencyInjector.CreateOverrider()
FakeDataStoreInjector:WhenCalled("GetAsync"):ThenCall(function()
error("HTTP Service 503: Simulated error.")
end)
local FakeDataStore = DependencyInjector.Inject({},FakeDataStoreInjector)
--Create the fake DataStoreService.
local DataStoreServiceInjector = DependencyInjector.CreateOverrider()
DataStoreServiceInjector:WhenCalled("GetGlobalDataStore"):ThenReturn(FakeDataStore)
local FakeDataStoreService = DependencyInjector.Inject({},DataStoreServiceInjector)
--Create the fake game.
local GameInjector = DependencyInjector.CreateOverrider()
GameInjector:WhenIndexed("GetService"):ThenReturn(function(_,Index)
if Index == "DataStoreService" then
return FakeDataStoreService
end
end)
local FakeGame = DependencyInjector.Inject({},GameInjector)
--Create the main injector.
local Injector = DependencyInjector.CreateOverrider()
Injector:WhenIndexed("game"):ThenReturn(FakeGame)
Injector:WhenCalled("warn"):ThenCall(function(Warning)
if string.match(Warning,"HTTP Service 503: Simulated error.") then
ProperErrorWarned = true
end
end)
--Create an inject the function.
local function Test()
local Worked,Return = pcall(function()
return game:GetService("DataStoreService"):GetGlobalDataStore():GetAsync("Thing")
end)
if not Worked then
warn("Failed because "..Return)
end
end
DependencyInjector.InjectEnvironmentVariables(Test,Injector)
--Run the assertions.
Test()
UnitTest:AssertTrue(ProperErrorWarned,"Error not warned.")
end)
After:
Used a cooler and more useful texture for my haze and updated a lot of lighting settings both in the beam and the environment, still tweaking it, I hope eventually I will make some of the best looking lava on Roblox for my showcase